user2984916
user2984916

Reputation: 23

HTAccess 301 Redirect Plus Query String Changed To A Path

http://www.domain.com/old-name-here?manufacturer=445 should display as:

http://www.domain.com/new-name-here/brand-name

If I enter the following htaccess code:

Redirect 301 /old-name-here?manufacturer=445 /new-name-here/brand-name-here

It does redirect properly via 301, but it keeps the query string on the end and only redirects the 1st folder...

Upvotes: 2

Views: 159

Answers (1)

anubhava
anubhava

Reputation: 785206

Redirect directive cannot match QUERY_STRING. You should use mod_rewrite rules.

You can use this rule in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On

RewriteCond %{QUERY_STRING} (^|&)manufacturer=45(&|$) [NC]
RewriteRule ^old-name-here/?$ /new-name-here/brand-name-here? [NC,L,R=301]

? in the end will strip any existing query string from target URI.

Upvotes: 0

Related Questions