简体   繁体   中英

htaccess rewrite works but how to redirect to the rewrite?

Hey so I've searched up and down through the questions without finding the answer to what I'm looking for. If this is a dupe I apologize, please direct me to the answer.

So I've set up my htaccess so that if someone types in:

www.example.com/menu

it loads the follow page " www.example.com/page.php ".

The problem I'm facing is that if someone types in:

www.example.com/page.php

directly, it doesn't change the URL to "www.example.com/menu" and just remains showing as "www.example.com/page.php"

How can I make it so that if person types in either "www.example.com/page.php" or "www.example.com/menu" it will always show the url as "www.example.com/menu"?

here's my htaccess:

RewriteEngine On
RewriteRule ^menu/?$ page.php [NC,L]

Put this code in your htaccess (in root folder)

RewriteEngine On

RewriteCond %{THE_REQUEST} \s/page\.php [NC]
RewriteRule . /menu [R=301,L]

RewriteRule ^menu$ /page.php [L]

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