2016-07-04 32 views
1

我与PHP工作,我想改变这个网址mydomain.com/index.php这个mydomain.com/home所以写了下面的代码:URL重写:更改mydomain.com/index.php到mydomain.com/home

RewriteEngine on 
RewriteRule home index.php 

当我去mydomain.com/home它的工作原理,但是当我去mydomain.com/index.php的URL不会更改为mydomain.com/home

我怎么能解决这个问题吗?

+0

您使用的笨? –

回答

1

尝试:

RewriteEngine on 
#externally redirect "/index.php" to "/home" 
RewriteCond %{THE_REQUEST} \s/index\.php 
RewriteRule^/home [L,R] 
#internally map "/home" back to "/index.php" 
RewriteRule home index.php 
+0

谢谢,它的工作原理。你能解释一下代码吗? – Prince

+0

请参阅代码中的注释。 – starkeen

+0

糟糕,我面临一个问题:即使我尝试访问一个看起来像这个'mydomain/folder/index.php'的链接,我被重定向到'mydomain/index.php' – Prince

1

RewriteEngine on 
RewriteBase/
RewriteRule index.php http://example.com/home [L,R=301] 
+0

什么是**和**? – starkeen

+0

这行代码来自我的.htaccess代码。我现在删除了该行,因为它是可选的。这是将默认路径设置为http://example.com/home –