I am creating a htaccess file, I currently have a long url looking like this:
domain.com/file.aspx?id=1000&AE=value1&PL=value2
I want to redirect it to look like:
seconddomain.com/directory/subdirectory/1000
(i.e. just use the value of the ID key passed).
This is what I'm using:
Rew开发者_如何学GoriteEngine on
RewriteCond %{QUERY_STRING} ^id=([0-9]+).*$
RewriteRule ^file.aspx$ http://seconddomain.com/directory/subdirectory/%1 [R=301,L]
However, what I end up getting is:
http://seconddomain.com/directory/subdirectory/1000?id=1000&AE=value1&PL=value2
i.e. the value of ID gets put in the correct spot -- however, the full query string is appended. I do not have a QSA flag.
What am I doing wrong?
Thank you in advance.
I think the query string is automatically appended if you don't set one yourself, try sticking a ?
at the end of the redirect path to override that and see if that helps
EDIT
Just to clarify your code would look like this:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^id=([0-9]+).*$
RewriteRule ^file.aspx$ http://seconddomain.com/directory/subdirectory/%1? [R=301,L]
精彩评论