2017-04-12 104 views
0

我想要映射网址:我在地址栏上输入网址http://help.localhost.com然后我会看到页面http://localhost.com/help.html,但地址栏上的网址没有更改(仍为help.localhost.com)。我用下面的代码:在Apache中通过htaccess重写URL

RewriteEngine on 
RewriteBase/
RewriteRule "localhost/help.html" "help.localhost.com" 

但是,它并没有为我工作。 任何人都可以帮我解决这个问题!

+0

我认为,如果你浏览http://help.localhost.com直接您得到相同的内容,http://localhost.com/help.php吧?如果是这样,你可以这样做:'RewriteRule ^(localhost.com /.*)$ http://$1.localhost.com [R = 301,L,NC]' – Lambasoft

+0

是的,绝对正确。但是,html文件,而不是php – user3697373

+0

当你在浏览器中直接访问'http:// help.localhost.com /'时,是什么行为? – anubhava

回答

0

您可以使用这些规则:

RewriteEngine on 
RewriteBase/

RewriteCond %{HTTP_HOST} ^(?:www\.)?matheval\.info$ [NC] 
RewriteRule ^/?help\.html$ http://help.matheval.info/ [L,NC,R=301] 
+0

它没有工作http://help.matheval.info(将localhost.com更改为matheval.info) – user3697373

+0

您在浏览器中输入了什么网址? – anubhava

+0

我输入了help.matheval.info,但浏览器通知没有任何内容。输入matheval.info/help.html – user3697373