开发者

Strange behavior change in mod_rewrite

开发者 https://www.devze.com 2022-12-15 13:51 出处:网络
In a .htaccess context, I have a simple rewriting rule : RewriteEngine on RewriteRule ^dir/([^/]+)/(.*) action/do.php?a=$1&b=$2 [L,QSA]

In a .htaccess context, I have a simple rewriting rule :

RewriteEngine on
RewriteRule ^dir/([^/]+)/(.*) action/do.php?a=$1&b=$2 [L,QSA]

dir and action are in the same directory, which is also my DocumentRoot.

When accessing http://example.org/dir/a/b the request should (and was) rewritten to http://example.org/action/do.php?a=a&b=b without redirection or anything visible.

However since I upgraded from Apache 1.3 + mod_php to Apache 2.2 (mpm_worker) + PHP FastCGI (don't know how it's related, but it seems to be), the precedent rule returns a 404 error :

The requested URL /var/www/action/do.php was not found on this server.

The DocumentRoot is now inserted in the request ! The file /var/www/var/www/action/do.php obviously doesn't exist开发者_如何学Go.

As a workaround, I changed the rule : (added a / at the beginning of the second part)

RewriteEngine on
RewriteRule ^dir/([^/]+)/(.*) /action/do.php?a=$1&b=$2 [L,QSA]

And it works (because fortunately in this case, I'm in the DocumentRoot directory).

Do you know what caused this behavior change ? Did you notice the same thing ?


Ok, I found what happened.

Actually, I was not in my DocumentRoot but in a VirtualDocumentRoot thanks to mod_vhost_alias.

The issue does not happen when using "real" virtual hosts.

0

精彩评论

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