当前位置: 动力学知识库 > 问答 > 编程问答 >

.htaccess - Old query String hard coded 301 url redirection using htaccess

问题描述:

I have recently changed CMS of my website and now looking to redirect old urls like:

oldpage.php?key=7cdb93c26

to some new urls but I want all of them in hard coded way and it should be a 301 redirect

I tried the following rules but none of them work for me

redirect 301 /oldpage.php?key=7cdb93c26 http://www.mynewsite.com/my-new-page.html

redirect 301 "/oldpage.php?key=7cdb93c26" http://www.mynewsite.com/my-new-page.html

RewriteRule ^oldpage.php?key=7cdb93c26$ http://www.mynewsite.com/my-new-page.html [L,R=301]

RewriteRule ^oldpage.php?key=7cdb93c26$ /my-new-page.html [L,R=301]

网友答案:

Try this

RewriteCond %{REQUEST_FILENAME} oldpage.php
RewriteCond %{QUERY_STRING} key=7cdb93c26
RewriteRule ^http://www.mynewsite.com/my-new-page.html [L,R=301]
网友答案:

I found the solution myself and here it is:

RewriteCond %{SCRIPT_FILENAME} oldpage.php
RewriteCond %{QUERY_STRING} key=7cdb93c26
RewriteRule ^(.*)$ http://www.mynewsite.com/my-new-page.html? [L,R=301]
分享给朋友:
您可能感兴趣的文章:
随机阅读: