简体   繁体   中英

.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. So the page www.mydomain.co.uk/tour/ should point towards www.mydomain.co.uk/ but without changing.

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

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. Replace the full URL with just a slash and it should work, ie:

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. 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],我认为它会起作用。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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