简体   繁体   中英

.htaccess redirect based on querystring

I've just launched a new worpdress site which replaces an old asp site.

While google is re-indexing i've been asked to make sure that key pages get redirected.

For example: www.egmont.co.uk/default.asp?pageid=3 needs to go to http://www.egmont.co.uk/who-we-are/what-we-do/books/

Googling has led me to construct the following, but it doesnt work, can anyone tell me why?:

RewriteEngine on
RewriteCond %{QUERY_STRING} pageid=3
RewriteRule /who-we-are/what-we-do/books/ [L,R=301]

You're close but remember that RewriteRule syntax is:

RewriteRule <pattern-to-match-in-uri> <target-uri> <flags>

You can try this rule:

RewriteEngine on

RewriteCond %{QUERY_STRING} ^pageid=3(&|$) [NC]
RewriteRule ^default\.asp$ /who-we-are/what-we-do/books/? [L,R=302,NC]
  • Make sure this rule is placed before other WP rewrite code.
  • Once you verify it is working you can change 302 to 301 .

Reference: Apache mod_rewrite Introduction

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