alioygur
alioygur

Reputation: 5464

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/page/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.

Upvotes: 1

Views: 381

Answers (2)

Felix Kling
Felix Kling

Reputation: 817128

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]

Upvotes: 3

Klaus Byskov Pedersen
Klaus Byskov Pedersen

Reputation: 121057

According to this article, you should be able to write:

RewriteRule ^index.php http://www.newsite.net/page/contact$1? [R=301,L]

Upvotes: 0

Related Questions