Redirect php page to another php page using 301 .htaccess

白昼怎懂夜的黑 提交于 2019-12-13 00:42:00

问题


I have a dynamic page that I need to redirect to another dynamic page in .htaccess.

I have tried different syntax for the redirect but nothing seems to work:

RewriteEngine on 
RewriteRule /index.php?p=page&page_id=store$ http://www.website.com/index.php [R=301]

OR

RewriteEngine on 
RewriteCond %{QUERY_STRING} ^p=page&page_id=store$
RewriteRule ^/index.php$ http://www.website.com/index.php? [L,R=301]

EDIT: I have an old php page in the shopping cart that I have transferred to the new address. So in order to preserve search engine page ranking I want to redirect old page to the new address. I want visitors who still visit www.website.com/index.php?p=page&page_id=store to be redirected to website.com/index.php

Thanks in advance!


回答1:


URI's that are fed to rewrite rules inside htaccess files always have the leading slash stripped off. So instead of /index.php, you have index.php, since htaccess files are essentially a per-directory case, similar to the <Directory> directive. So you want the second option but without the leading slash:

RewriteEngine on 
RewriteCond %{QUERY_STRING} ^p=page&page_id=store$
# no slash --v
RewriteRule ^index.php$ http://www.website.com/index.php? [L,R=301]


来源:https://stackoverflow.com/questions/12460515/redirect-php-page-to-another-php-page-using-301-htaccess

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