I need to rewrite the following types of URLs:
http://www.gocruise.co.uk/fusion/detailline3.pl?lineid=13&sid=6924&ccid=Fred+Olsen
into:
http://www.gocruise.co.uk/fred-o开发者_如何转开发lsen
using an Apache RewriteRule. I have been trying to get to grips with these rewrites as quick as i can but have run out of time. Any help will be much appreciated.
(the main bit im struggling with is how to manage the multiple parameters)
You probably want it the other way round: A request of /fred-olsen
comes in, and you want to redirect the user to the longer URL. This is pretty simple:
# in the Server Configuration or VHost Configuration:
RewriteRule ^/fred-olsen$ /fusion/detailline3.pl?lineid=13&sid=6924&ccid=Fred+Olsen [R=301,L]
or:
# in the .htaccess file of the DocumentRoot
RewriteRule ^fred-olsen$ fusion/detailline3.pl?lineid=13&sid=6924&ccid=Fred+Olsen [R=301,L]
Unless lineid and sid are always going to be the same values, or they're not important to the code, I don't think it's going to work. Typically, url rewrites include all the parameters, so you'd end up with something like http://www.gocruise.co.uk/13/6924/fred-olsen
Alright, the following rules should do what you're asking. The other two parameters will be sent in the querystring. The only other way would be to add them into the URL, which it doesn't seem like that is what you want.
# http://www.gocruise.co.uk/fusion/detailline3.pl?lineid=13&sid=6924&ccid=Fred+Olsen
# redirects to ->
# http://www.gocruise.co.uk/Fred-Olsen?lineid=13&sid=6924
RewriteEngine On
RewriteCond %{REQUEST_URI} /fusion/detailline3.pl
RewriteCond %{QUERY_STRING} (.*)&ccid=(\w*)\+(\w*)$
RewriteRule (.*) /%2-%3?%1 [L,R=301]
精彩评论