重写apache的规则

时间:2013-01-23 02:56:44

标签: php apache mod-rewrite url-rewriting rewrite

鉴于此链接:localhost / app / forms / enroll.php。 我希望它在我访问/注册时呈现。

例如:localhost / register将显示localhost / app / forms / enroll.php

基本上我有这段代码:

RewriteEngine On
RewriteBase /
RewriteRule register app/forms/enroll.php

在我的代码中,我调用了localhost / enroll.php,我想将其重定向到/app/enroll.php但是我想再次显示链接(localhost / register)。

所以我需要再次回复上面提到的RewriteRule。

添加此规则不起作用

RewriteRule enroll.php register [R]

也是这个

RewriteRule enroll.php app/forms/enroll.php [C]
RewriteRule app/forms/enroll.php register 

注意:我需要一个解决方法,而不必更改代码中的链接。 :)

1 个答案:

答案 0 :(得分:0)

如果我理解正确,您不必多次重定向。只是第一次静默地映射,如下所示:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI}  !enroll.php         [NC]
RewriteRule ^register/?$  app/forms/enroll.php  [L]

它将以静默方式重定向

http://localhost/register(此网址始终显示在浏览器中)

要:

http://localhost/app/forms/enroll.php