.htaccess: Redirect without changing url

后端 未结 3 1119
暗喜
暗喜 2020-12-09 08:51

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/ s

相关标签:
3条回答
  • 2020-12-09 09:29

    Try just to change [L] to [P] and I assume it will work.

    0 讨论(0)
  • 2020-12-09 09:33

    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]
    
    0 讨论(0)
  • 2020-12-09 09:38

    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.

    0 讨论(0)
提交回复
热议问题