2010-06-03 90 views
2

我有localhost上以下的目录结构:的.htaccess公用文件夹

http://localhost/testing/

目录结构测试的内部存在如下:

/testing/public 
/testing/public/index.php 
/testing/public/img 
/testing/public/css 
..etc for the js and swf directories 

.htaccess文件是里面的测试文件夹和内容如下:

Options +FollowSymLinks 
RewriteEngine on 
RewriteBase /testing/ 

RewriteRule ^public$ public/ [R,QSA] 
RewriteRule ^public/$ public/index.php?state=public [L,QSA] 

RewriteRule ^stackoverflow$ stackoverflow/ [R,QSA] 
RewriteRule ^stackoverflow/$ public/index.php?state=stackoverflow[L,QSA] 

我使用PHP和/testing/public/index.php文件,我想测试$ _GET ['state']确实正在保存变量。

当我试图测试一下:

http://localhost/testing/public

$ _GET [ '状态']是不是在所有

http://localhost/testing/stackoverflow

确实呼应的是,$发现_GET ['state']等于'stackoverflow'。

我在这里丢失什么?为什么我在第一个链接中无法获得state = public?谢谢您的帮助!

回答

1

这对我的系统工作正常,但我认为你有一个与实际的文件系统目录具有相同名称的重写规则陷入困境。文件系统通常优先。所以当你加载'/ testing/public'时,它只会加载/testing/public/index.php,而不运行你的规则。

尝试改变规则是:

RewriteRule ^public_$ public_/ [R,QSA] 
RewriteRule ^public_/$ public/index.php?state=public [L,QSA] 

导航到“测试/ public_”,如果打印出“公共”如预期那么你就会知道那是你的问题。

+0

你说得对,你确实优先!最后,我可以用一个理智的头脑睡觉......哈哈。谢谢Nathan。我将目录的名称完全更改为'public_content'以完全避免它。再次谢谢你! – ninu 2010-06-03 04:15:44