【问题标题】:.htaccess with public folder.htaccess 与公用文件夹
【发布时间】:2010-06-03 03:36:04
【问题描述】:

我在 localhost 上有一个目录结构如下:

http://localhost/testing/

testing内部存在如下目录结构:

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

testing文件夹中有一个.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['state'] 根本找不到但是

http://localhost/testing/stackoverflow

确实表明 $_GET['state'] 等于 'stackoverflow'。

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

【问题讨论】:

    标签: .htaccess mod-rewrite


    【解决方案1】:

    这在我的系统上运行良好,但我认为您会遇到与实际文件系统目录同名的重写规则的麻烦。文件系统通常优先。因此,当您加载 '/testing/public' 时,它只会加载 /testing/public/index.php 而不运行您的规则。

    尝试将规则更改为:

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

    导航到“testing/public_”,如果按预期打印出“public”,那么您就会知道这是您的问题。

    【讨论】:

    • 你说的没错,它确实优先!终于可以安心入睡了……哈哈。谢谢内森。我将目录的名称完全更改为“public_content”以完全避免它。再次感谢您!
    猜你喜欢
    • 2017-10-12
    • 1970-01-01
    • 1970-01-01
    • 2017-05-21
    • 1970-01-01
    • 2017-07-27
    • 1970-01-01
    • 1970-01-01
    • 2017-01-23
    相关资源
    最近更新 更多