How to remove the query string?
Note: i little speak english
I have a problem with mod_rewrite
.
I want to replace my site name, I want this URL
http://www.oldsite.com/index.php?v=contact
rewritten to URL
http://www.newsite.com/pag开发者_StackOverflowe/contact with 301 rewrite.
I'm doing it this way:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{QUERY_STRING} v=contact
RewriteRule ^index.php http://www.newsite.net/page/contact [R=301,L]
But I'm getting the query http://www.newsite.net/page/contact?v=contact
.
I dont want ?v=contact
, I want http://www.newsite.net/page/contact
.
From the documentation:
Note: Query String
The Pattern will not be matched against the query string. Instead, you must use a RewriteCond with the%{QUERY_STRING}
variable. You can, however, create URLs in the substitution string, containing a query string part. Simply use a question mark inside the substitution string, to indicate that the following text should be re-injected into the query string. When you want to erase an existing query string, end the substitution string with just a question mark. To combine a new query string with an old one, use the[QSA]
flag.
So you should probably have:
RewriteRule ^index.php http://www.newsite.net/page/contact? [R=301,L]
According to this article, you should be able to write:
RewriteRule ^index.php http://www.newsite.net/page/contact$1? [R=301,L]
精彩评论