问题
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