开发者

.htaccess with public folder

I have a directory structure with the following on localhost:

http://localhost/testing/

A directory structure exists inside of testing as follows:

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

A .htaccess file is inside the testing folder and the contents are as follows:

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]

I am using PHP and inside of the /testing/public/index.php file I wanted to test that the $_GET['state'] is indeed saving the variable.

When I try to test out:

http://localhost/testing/public

$_GET['state'] is not found at all BUT

http://localhost/testing/stackoverflow

does indeed echo out that $_GET['state'] equals 'stackoverflow'.

What am I missing here??? Why is it that I cannot get the state开发者_如何学Python=public in the first link? Thanks for the help!


This works fine on my system, but I think you are getting into trouble by having a rewrite rule with the same name as an actual file system directory. The file-system will generally take precedence. So when you load up '/testing/public' it just loads /testing/public/index.php without running your rule at all.

Try changing the rule to this:

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

Navigate to 'testing/public_', if that prints out 'public' as expected then you will know that was your problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜