开发者

mod_rewrite ignores [L]

开发者 https://www.devze.com 2022-12-16 16:30 出处:网络
I want to be able to rewrite this http://localhost/.../identicon/f528764d624db129b32c21fbca0cb8d6.png to

I want to be able to rewrite this

http://localhost/.../identicon/f528764d624db129b32c21fbca0cb8d6.png

to

http://localhost/.../identicon.php?hash=f528764d624db129b32c21fbca0cb8d6

so I add to the /.../.htaccess so this is it:

RewriteEngine On
RewriteRule ^resource/ - [L]
RewriteRule ^identicon/(.+)\.png$ identicon.php?hash=$1 [QSA,L]
RewriteRule ^(.*)$ index.php?t=$1 [QSA,L]

Which doesn't work for some开发者_如何学运维 reason because it redirects it to index.php?t=identicon.php; even though the L flag is set! Why?


Add a condition to the last rule to exclude requests that can be mapped to existing files:

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

That is necessary because the L flag generates an internal redirect with the new URL as the request URL:

Remember, however, that if the RewriteRule generates an internal redirect (which frequently occurs when rewriting in a per-directory context), this will reinject the request and will cause processing to be repeated starting from the first RewriteRule.


(Not correct answer; left for reference)


I just figured out what may be the issue - it's something that thwarted me for a long time.

Depending on your server settings, it very well may be interpreting identicon/xxx.png as a request to identicon.php/xxx.png, assuming that the PHP extension is what you wanted. Try going to /index instead of /index.php - if it loads the PHP file, this is the issue affecting you.

This is the MultiViews Apache option, and it's stupid, but it has to be enabled specifically. Go into your site configuration file and see where it is enabled, and remove it.

If you don't have total control over your server configuration, the following may work in .htaccess (depending, ironically, on your server configuration).

Options -Multiviews
0

精彩评论

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

关注公众号