views:

47

answers:

2

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

http://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.

A: 

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]
Hatchware
A: 

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.

Terry