Dynamic 301 Redirect

为君一笑 提交于 2019-12-11 05:04:02

问题


We made a mistake in the scope of our dynamic pages on a new site, and have some incorrect pages already spidered in Google.

I need to redirect the following format: http://www.domain.com/dir/dir/?q=120

To this format: http://www.domain.com/dir/dir/?p=120

Only difference is the 'q' needs to be a 'p'.

RewriteEngine is on, as I've already consolidated traffic from domain.com to www.domain.com

This is what I have in my root .htaccess file:

Options +FollowSymLinks 
RewriteEngine on 
RewriteCond %{HTTP_HOST} ^centerline.com [NC] 
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301] 
RewriteRule ^(/leadership/detail/)\?q=([0-9]+)$    $1?p=$2 [R=301, L]

回答1:


Try this:

RewriteCond %{QUERY_STRING} q=([0-9]+)$
RewriteRule ^(.*)$ /$1?p=%1 [L,R=301]

You'll need the RewriteCond as apache doesn't allow matching against the querystring in a RewriteRule

EDIT

RewriteCond %{REQUEST_URI} ^/leadership/detail/$
RewriteCond %{QUERY_STRING} q=([0-9]+)$ 
RewriteRule ^(.*)$ /$1?p=%1 [L,R=301]


来源:https://stackoverflow.com/questions/5721544/dynamic-301-redirect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!