开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜