【发布时间】:2014-03-23 11:43:38
【问题描述】:
这是我的文件夹结构
htdocs
-> testing
->index.php
->.htaccess
在 index.php 里面我有这段代码
<?php
if(isset($_SERVER['PATH_INFO'])) {
echo $_SERVER['PATH_INFO'];
}
?>
在 .htaccess 里面我有这段代码
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php/$1 [NC,L]
这是我的问题:
在上面的htaccess重写规则中,它将我的地址localhost/testing/HelloWorld链接到localhost/testing/index.php/HelloWorld
有可能做这样的事情吗?当用户输入 localhost/testing/index.php/HelloWorld 我希望浏览器隐藏单词 index.php 并且只显示类似 localhost/testing/HelloWorld
我尝试通过在 .htacces 文件中添加另一条规则将链接 localhost/testing/index.php/HelloWorld 重定向到 localhost/testing/HelloWorld 但我得到“网页有重定向循环”错误信息。
添加新规则后,.htacces 文件如下所示
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php/$1 [NC,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^index.php/(.+)$ /testing/$1 [R]
有什么方法可以让我的链接变成这样吗?非常感谢您的帮助。
【问题讨论】:
标签: .htaccess mod-rewrite rewrite