简体   繁体   English

htaccess重写有效,但是如何重定向到重写?

[英]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: 因此,我设置了htaccess,以便有人输入时:

www.example.com/menu www.example.com/menu

it loads the follow page " www.example.com/page.php ". 它会加载以下页面“ 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" 直接将其更改为“ www.example.com/menu”,而不会继续显示为“ 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"? 我如何才能做到,如果有人输入“ www.example.com/page.php”或“ www.example.com/menu”,则该网址始终显示为“ www.example.com/menu”?

here's my htaccess: 这是我的htaccess:

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

Put this code in your htaccess (in root folder) 将此代码放在您的htaccess中(在根文件夹中)

RewriteEngine On

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

RewriteRule ^menu$ /page.php [L]

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

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