用htaccess重写URL - 如何显示假网址?

时间:2012-09-18 07:45:17

标签: .htaccess url-rewriting

我在htacces文件中有这样的代码

<IfModule mod_rewrite.c>
RewriteEngine on
# this stops looping
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]
# this redirects the browser:
RewriteRule !^/?UL/india/ /UL/india/ [L,R=301]
RewriteRule ^/?UL/india/ /UL/index.php [L]
</IfModule>

但访问localhost/UL/时,它会一直显示“页面未正确重定向”。有什么问题?

对于UL目录的每个请求,我希望在地址栏中显示localhost/UL/india/ 但是应该执行的文件是localhost/UL/index.php

1 个答案:

答案 0 :(得分:0)

在规则中添加L标记并停止循环:

# this stops looping
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]

# this redirects the browser:
RewriteRule !^/?UL/india/ /UL/india/ [L,R=301]

然后,在此之后,您希望匹配/UL/india/并提供index.php文件:

RewriteRule ^/?UL/india/ /UL/index.php [L]