简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM