Htaccess 将旧页面重定向到新页面 [英] Htaccess Redirection Old Page to New Page
本文介绍了Htaccess 将旧页面重定向到新页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我更改了其中一个页面的 slug,我想将旧页面重定向到新页面.
I have changed one of my pages' slug, i want to redirect the old one to new one.
我在 htaccess 文件中写的是:
What i've written in htaccess file is :
Redirect 301 /event.php?event_id=10&slug=old-slug-example http://www.mywebsite.com/event/10/new-slug-example
但是当我尝试访问旧链接时,浏览器返回:
But when i try to reach to old link, browser returns this :
http://www.mywebsite.com/event/10/new-slug-example?event_id=10&slug=old-slug-example
如何解决,谢谢
推荐答案
在重定向目标的末尾添加一个?
:
Add a ?
at the end of the redirect target:
# here -------------------------------------------v
http://www.mywebsite.com/event/10/new-slug-example?
但是你最终会得到一个丑陋的?
.您可以使用 mod_rewrite 并且它不会显示在浏览器的 URL 地址栏中:
But then you'll end up with an ugly ?
at the end. You could resort to mod_rewrite and it won't show up in the browser's URL address bar:
RewriteEngine On
RewriteCond %{QUERY_STRING} event_id=10&slug=old-slug-example
RewriteRule ^/?event.php$ http://www.mywebsite.com/event/10/new-slug-example? [L,R=301]
这篇关于Htaccess 将旧页面重定向到新页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文