I am not able to access the files(images, css) inside my application and root folder of codeigniter. I have checked the permissions and the links. Everything seems to be fine but it gives a 404 error when trying to load the file. I even tried to load the link directly. All files seems to be loading from the assets but not from the root or application folder.
.htaccess file :
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
I am not sure what direction to look in.
As a matter of fact they were working fine few days back, I haven't made any changes in the htaccess file.
Any help wil be appreciated.
Thanks.
One of the more common setups would be having it all like this:
Filestructure:
/docroot
- /assets
+ /css
+ /js
+ /img
+ application
+ system
* .htaccess
* index.php
.htaccess (v1):
RewriteEngine on
RewriteCond $1 !^(index\.php|images|assets|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
or the more flexible way:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
and now in your markup you gotta load:
<link rel="stylesheet" href="/assets/css/whatever.css"></link>
<script src="/assets/js/bla.js"></script>
<img src="/assets/img/logo.png" alt="Nice Logo">
As for files not being accessible within the application folder, that's due to a .htaccess file in that folder denying all access in general. To prevent unintended file exposal.
And if you want to access files directly in the docroot, you would have to change to the second .htaccess version
Related
I have a wordpress website physically located in the "wordpress" subfolder of the root folder of the website. I manage to hide the subfolder "wordpress" in the URL with the following code:
.htaccess on root folder
RewriteEngine On
RewriteBase /
RewriteRule ^$ wordpress/ [L]
RewriteRule ^(.*)$ wordpress/$1 [L]
.htaccess in wordpress subfolder
RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]
However, I have another website in another subfolder let's call it "other-wp" and this needs to remain as it is, with the URL pointing to:
https://mywebsite.com/other-wp/
Since I managed to hide the "wordpress" folder in the URL, I am unable to acces my "other-wp" it says the page doesn't exist.
I'm not skilled with coding for .htaccess so i don't know what i need to do to fix it.
Could you help?
You need to implement an exception for that second resource:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/other-wp
RewriteRule ^/?(.*)$ /wordpress/$1 [L]
I also made some other modifications to that top level configuration file, just smaller optimizations. In general you should check if you can place such global rules in the actual http server's host configuration. Using distributed configuration files (".htaccess") is just a fallback if you have no access to the real configuration. They work, but come with disadvantages.
I have the following code in my .htaccess file:
RewriteEngine on
RewriteCond %{HTTP_HOST} mysitedomain\.com [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ /web/$1 [L]
I'm currently using CPanel and CPanel does not allow you to set a new Document Root. So have my drupal files in my CPanel "public_html" directory with the composer.json files etc..and web directory that has all the Drupal related files. I am trying to get the site vistors to rewrite or redirect to www.mysitedomain.com/web for subsequent pages.. I tried the code below but does not seem to work.. Am i missing something?
To be specific.... I need the site to 1. load www.mysitedomain.com/web when www.mysitedomain.com is requested. 2. And ensure /web is is front of every subsequent request page request within the site (ie. www.mysitedomain.com/web/products should load instead of www.mysitedomain.com/products)
I am not sure what your question is, but I think you need something like this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
What it does: If the URL does not resolve to a file or directory in the present directory, put index.php in front of it.
I'd assume your index.php would then include the Drupal framework.
A development proyect in http://localhost/myfolder has references to /assets/css/styles.css which is the site in production.
I want to call it like: http://localhost/myfolder/
I have this .htaccess in apache webroot folder c:\wamp\www:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ /myfolder/$1 [L,QSA]
And it works ok when is, as I said in webroot folder.
When I move this .htaccess to /myfolder/.htaccess it does nothing.
What I have to change in this .htaccess to work also inside myfolder?
Thank you
Because it's imposible to manage absolute paths refereds to root from a subfolder (as Anubhava said), I decide to focus the problem with an /.htaccess and a RewriteCond that work only when we request the specific subfolder.
SOLUTION: (/.htacces finally is in root folder).
RewriteEngine on
# ConfiguraciĆ³n Myfolder
RewriteCond %{REQUEST_FILENAME} !-f
# Fix is the line below ---- FIX ------
RewriteCond %{REQUEST_URI} ^/myfolder/.*$
RewriteRule ^(.+)$ /myfolder/$1 [L,QSA]
In the other way, without the rewrite condition, it was affecting all requests.
This is better fix than the subfolder one, because you can download the production .htaccess and have no need to touch it.
Hope this help to others.
I have a problem with my routes. I have my images in sources/ folder but when the image is missing it cause to load the website and future problem with system overloading.
Htaccess:
RewriteCond $1 !^(index\.php|robots\.txt|sources|uploads|captcha|sitemap\.xml|_gapi|robots\.txt|googleaac809c6bcbeb4e8\.html|googlebaf6b56ae3013092\.html|feeds|temp)
RewriteRule ^(.*)$ /index.php?/$1 [L,QSA]
This should cause to load files from those folders - working well by this point
But when there is image missing for example:
<img src="uploads/non_existing_image.jpg"> the image wont load but when I copy the URL the website will load correctly and after some time my server ends up with 500 Error.
Is there any way how to solve this in htaccess/php ?
I want to end up with 404 error on that link
Don't use .htaccess for this, just Add the index.html file to your images folder also add the index.html in CSS and JavaScript folder. When someone try load you folder index.html is auto load and didn't allow your images etc.
It will give result like this
i also use a htaccess file with codeigniter, even though mine is quite smaller then yours:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
to explain: RewriteEngine On enables the rewriting of the url,
the RewriteCond %{REQUEST_FILENAME} !-f tells htaccess that the requested file should not be an existing file,
the RewriteCond %{REQUEST_FILENAME} !-d tells htaccess that the requested file should not be an existing directory.
this way you dont need to exclude all the seperate files and/or extentions and/or directories.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
Just add this to your .htaccess file
I am trying to remove the index.php from the url in codeigniter. Rewrite mod scripts are all over the place but I can't find the .htaccess file!! I tried looking in the root directory and everywhere else, but no luck.
From what I read it should be in application folder and when I go there i find the .htaccess file and all it has is deny from all. This is not the same content every one else is sharing online before modification.
Please advise.
Actually you don't find it; you create it along side with your index.php file with this contents:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
In the above example, any HTTP request other than those for index.php,
images, and robots.txt is treated as a request for your index.php
file.
Reference.
The solution is as follows ( for future references)
Create the .htaccess file in the root of the codeigniter application (where you got system, application, etc folders).
Paste this code in it:
RewriteEngine on
RewriteCond $1 !^(index.php|resources|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Open config.php and change index = "index.php" to "". Things should work now.