.htaccess:重定向而不更改 url

编程入门 行业动态 更新时间:2024-10-23 21:24:53
本文介绍了.htaccess:重定向而不更改 url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我希望将 URL 重定向到同一域中的不同页面,但浏览器不会更改 URL.所以页面 www.mydomain.co.uk/tour/ 应该指向 www.mydomain.co.uk/ 但不改变.

I would like to have a URL be redirected to a different page on the same domain but without the browser changing the URL. So the page www.mydomain.co.uk/tour/ should point towards www.mydomain.co.uk/ but without changing.

我在 Stackoverflow 上查看了很多类似的问题,但所有解决方案似乎都为我更改了 URL.

I have looked at a lot of similar questions on Stackoverflow but all the solutions seem to change the URL for me.

代码:

RewriteEngine On Options +FollowSymLinks RewriteCond %{REQUEST_URI} ^/tour RewriteRule ^(.*)$ www.mydomain.co.uk/ [L]

推荐答案

因为您在重写规则中提供了完整的 URL,所以它会自动被视为重定向.用斜杠替换完整的 URL,它应该可以工作,即:

Because you provide a full URL in your rewrite rule it is automatically treated as a redirection. Replace the full URL with just a slash and it should work, i.e.:

RewriteCond %{REQUEST_URI} ^/tour RewriteRule ^(.*)$ / [P]

您甚至可以将其缩短为:

You can even shorten it down to:

RewriteEngine on RewriteRule ^/?tour.* / [P]

更多推荐

.htaccess:重定向而不更改 url

本文发布于:2023-10-31 12:55:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546148.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:而不   重定向   htaccess   url

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!