简体   繁体   English

.htaccess:重定向而不更改URL

[英].htaccess: Redirect without changing url

I would like to have a URL be redirected to a different page on the same domain but without the browser changing the URL. 我想将URL重定向到同一域上的不同页面,但浏览器不会更改URL。 So the page www.mydomain.co.uk/tour/ should point towards www.mydomain.co.uk/ but without changing. 因此, www.mydomain.co.uk/tour/页面应指向www.mydomain.co.uk/但不得更改。

I have looked at a lot of similar questions on Stackoverflow but all the solutions seem to change the URL for me. 我在Stackoverflow上看了很多类似的问题但是所有的解决方案似乎都改变了我的URL。

CODE: 码:

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

Because you provide a full URL in your rewrite rule it is automatically treated as a redirection. 因为您在重写规则中提供了完整的URL,所以它会自动被视为重定向。 Replace the full URL with just a slash and it should work, ie: 用一个斜杠替换完整的URL,它应该工作,即:

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

You can even shorten it down to: 您甚至可以将其缩短为:

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

1- Use [P] instead of [L] 2- Use $s at the end of second line to have a set of urls redirects and remove / at the end of it too. 1-使用[P]而不是[L] 2-在第二行末尾使用$ s以使一组URL重定向并在其末尾删除/。 the code will look like this: 代码看起来像这样:

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

which treats with more than the index page of the folder tour. 与文件夹之旅的索引页面相比更多。

尝试将[L]更改为[P],我认为它会起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM