UPDATE: Problem solved
After many hours, I finally understood that the problem were in folder permission (757 instead of 755).
Damn, I feel like a idiot, but at least, problem solved :)
Thanks everyone!
I'm having a weird problem with my .htaccess and mod_rewrite.
Currently, I've the following .htaccess on my root:
Options +FollowSymLinks
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . /index.php [NC,L]
The problem is :
I want to be able to access any existing file.
ie: mysite.com/anydir/myfile.png -> open the anydir/myfile.png
- mysite.com/anydir/script.php -> open anydir/script.php
- mysite.com/file.png -> open file.png
- mysite.com/notadir/imnotafile -> rewrite
But, everything works except the second point. I've a file.php
in my test
folder, but when I do mysite.com/test/file.php
, it keep rewriting it, and it shouldn't...
What I'm I doing wrong?
Probably do the trick:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
UPDATE 1
At this part of code:
RewriteRule ^index\.php$ - [L]
[L]
Stop the rewriting process immediately and don't apply any more rules. So,
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . /index.php [NC,L]
Are not interpreted.
UPDATE 2:
The server will follow symbolic links:
Options +FollowSymLinks
The server will disable multi views:
Options -MultiViews
Rewrite engine will be enabled:
RewriteEngine On
Base directory for rewrite will be /
:
RewriteBase /
If request match a not existing file, continue:
RewriteCond %{REQUEST_FILENAME} !-f
If request match a not existing directory, continue:
RewriteCond %{REQUEST_FILENAME} !-d
Rewrite to index.php
, in a not sensitive case, and stop execution of next rules:
RewriteRule index.php [NC,L]
So, try the follow:
Options +FollowSymLinks
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule index.php [NC,L]
If you just want to get rid of the 404 error you could use
ErrorDocument 404 index.php
If you want to rewrite every directory i guess you should remove;
RewriteCond %{REQUEST_FILENAME} !-d
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.