开发者

Unexpected htaccess behaviour (mod_rewrite and apache)

开发者 https://www.devze.com 2023-01-02 13:09 出处:网络
Yeah, mod_rewrite is driving me crazy. Here is the problem: my htaccess RewriteCond %{REQUEST_FILENAME} !-f

Yeah, mod_rewrite is driving me crazy.

Here is the problem:

my htaccess

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$    index.php?url=$1 [L,QSA]

when i try to access the page advantix (so address was www.mywebsite.com/advantix), i'm being redirected to advantix/?url=advantix

Looking at the access log, i have a suspicious 301 in the middle

"GET /advantix HTTP/1.1" 301 335 "-" "Mozilla/5.0"
"GET /advantix/?url=advantix HTTP/1.1" 200 186 "-" "Mozilla/5.0"

There is one important detail: advantix is a directory.

So, if i comment that rule, advantix goes to the folder and list the files.

Why it applies automatically the / if there's a 开发者_运维百科folder matching?

I don't want to reach the folder, i want to reach index.php?url=advantix with a call to advantix.

I have the rewriteLogs too, but they didn't help more. My vhost conf has Directory tag with Options All, if helps, i don't know much about that.


Turn off the DirectorySlash Apache directive. This seems to be causing the 301 redirect.

DirectorySlash Off
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]


Try this once:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$    index.php?url=$1 [L,QSA]


I had a similar problem. My solution is to stop rewriting URL on "bad" paths (directories without slash at the end):

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*[^/])$ $1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*?)/*$ index.php?route=$1 [L,QSA]
0

精彩评论

暂无评论...
验证码 换一张
取 消