.htaccess:重定向而不更改 url [英] .htaccess: Redirect without changing url

查看:36
本文介绍了.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 ^(.*)$ 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] 

您甚至可以将其缩短为:

You can even shorten it down to:

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

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆