重定向而不更改网址

重定向而不更改网址

本文介绍了.htaccess:重定向而不更改网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望将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 ^(.*)$ http://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]

您甚至可以将其缩短为: / p>

You can even shorten it down to:

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

这篇关于.htaccess:重定向而不更改网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 21:00