.htaccess - 301 重定向到新的 url,然后默默地重定向回来以隐藏丑陋的 url
我刚刚更改了 url 方案,因此 example.com/ugly 现在是 example.com/nice
example.com/ugly 仍然处理请求 - .htaccess 有这个规则:
RewriteRule ^nice$ example.com/ugly [PT,L,QSA]
这很有效。
现在我想将 example.com/ugly 重定向到 example.com/nice,但仍然让 example.com/ugly 处理请求。像这样的事情:
- 将 example.com/ugly 重定向到 example.com/nice (301)
- 在内部将 example.com/nice 重定向到 example.com/ugly,而不让用户知道,并且不重复步骤 1
执行此引导的简单方法当然是循环。有没有办法用 .htaccess 做到这一点?如果没有,还有其他办法吗?
I just changed url schemes, so example.com/ugly is now example.com/nice
example.com/ugly still handles the request - .htaccess has this rule:
RewriteRule ^nice$ example.com/ugly [PT,L,QSA]
This much works.
Now I'd like to redirect example.com/ugly to example.com/nice, but still have example.com/ugly handle the request. Something like this:
- Redirect example.com/ugly to example.com/nice (301)
- Internally redirect example.com/nice to example.com/ugly, without letting the user know, and without repeating step 1
Simple ways of doing this lead to looping of course. Is there a way to do this with .htaccess? If not, is there another way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我所知道的最好的方法是在目标文件中使用 PHP。以下是您想要添加的内容:
显然您需要在其中添加一些其他变量来处理任何请求,但这是基本思想。
The best way I know of is using PHP in the target file. Here's approximately what you'd want to add:
Obviously you need to add some other variables in there to handle whatever requests, but that's the basic idea.