开发者

Why does this mod_rewrite expression not append the existing query string correctly?

开发者 https://www.devze.com 2022-12-20 21:15 出处:网络
I\'m a real newbie regarding mod_rewrite so please don\'t laugh. I am using this tool for testing: http://civilolydnad.se/projects/rewriterule/

I'm a real newbie regarding mod_rewrite so please don't laugh. I am using this tool for testing: http://civilolydnad.se/projects/rewriterule/

Basically I want to rewrite

http://hostname/spanish/whatever/

into

http://hostname/whatever/?lang=es

Here's the best I could come up with:

RewriteRule ^spanish/(.*)$ $1?lang=es [QSA,L,NC]

which seems to work except when the requested page already has parameters. In that case

h开发者_JAVA百科ttp://hostname/spanish/gallery/photos/?page=2

gets rewritten as

http://hostname/spanish/gallery/photos/?page=2?lang=es

Can anyone help this confused newbie? Thank you very much.


Basically, the tool is misleading, because the rule was proven to be correct, as written, when used on a real server environment. Thanks to all.


Something like this should help.

# Remove query strings from URL
RewriteCond %{THE_REQUEST} ^GET\ /.*\;.*\ HTTP/
RewriteCond %{QUERY_STRING} !^$
RewriteRule .* http://yourdomain.com%{REQUEST_URI}? [R=301,L]
0

精彩评论

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

关注公众号