简体   繁体   English

使用htaccess更改网址

[英]Using htaccess to change url

I want to change a url like: 我想更改一个网址,例如:

dynamicdomain.com/mypage dynamicdomain.com/mypage

to

dynamicdomain.com/mydashboard dynamicdomain.com/mydashboard

I want to display the content of mypage but the url that the users will see on the browser will contain mydashboard . 我想显示mypage的内容,但用户将在浏览器中看到的url包含mydashboard How do I do this using .htaccess . 我如何使用.htaccess做到这一点。

I tried using this: 我尝试使用此:

RewriteEngine On Redirect 301 /mydashboard /mypage

but this redirects the url: 但这会重定向网址:

dynamicdomain.com/mydashboard

to

dynamicdomain.com/mypage

Edit: Here is another example on what I want to achieve: I have a folder mypage which can be accessed as: http://dynamicdomain.com/mypage/ 编辑:这是我要实现的另一个示例:我有一个文件夹mypage ,可以通过以下方式访问: http : //dynamicdomain.com/mypage/

I want the users to see http://dynamicdomain.com/mydashboard/ ( mydashboard folder doesn't exists) when they access http://dynamicdomain.com/mypage/ 我希望用户看到http://dynamicdomain.com/mydashboard/mydashboard文件夹不存在),当他们访问http://dynamicdomain.com/mypage/

can someone point me in the right direction. 有人可以指出我正确的方向。 Thanks. 谢谢。

Try these directives: 尝试以下指令:

RewriteEngine On
RewriteRule ^mypage$ /dashbord [NC,L]

Redirect directive does an external redirect (redirects a URL to another URL) . Redirect指令进行外部重定向(将一个URL重定向到另一个URL) To redirect "dashboard" internally to "/mypage" , you need to use the RewriteRule directive of the Rewrite module. 要将内部的“ dashboard”重定向到“ / mypage” ,需要使用Rewrite模块的RewriteRule指令。

Put this in your htaccess file : just after IfModule closes 将其放在您的htaccess文件中:IfModule关闭后

Redirect 301 /mypage http://www.dynamicdomain.com/mydashboard 重定向301 / mypage http://www.dynamicdomain.com/mydashboard

This will work for you. 这将为您工作。

thanks 谢谢

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

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