【问题标题】:403 Error when using htaccess rewrite使用 htaccess 重写时出现 403 错误
【发布时间】:2012-12-18 23:44:09
【问题描述】:

我有一个 htaccess 文件,它将所有请求重定向到 /public/index.php。

AuthType Basic
AuthName "Access to /testsite"
AuthUserFile /kunden/homepages/28/d446685396/htpasswd
Require user oglover

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . public/index.php [L]

它适用于所有请求,例如www.mywebsite.com/aboutus、www.mywebsite.com/contact、www.mywebsite.com/news 等......但如果我访问 www.mywebsite.com/,我会收到 403 禁止错误。一切都很好,直到我搬到一个新的网络主机上,我不知道如何解决这个问题。

【问题讨论】:

    标签: .htaccess mod-rewrite url-rewriting


    【解决方案1】:
    RewriteRule . public/index.php [L]
    

    此规则中的正则表达式 . 表示“字符串中的任何单个字符”,这会导致您的问题。当您请求www.mywebsite.com/ 时,正则表达式将与空字符串匹配(请参阅手册中的What's being matched?)。正则表达式不匹配,因此不应用规则,因此服务器尝试提供根的索引,这是被禁止的。

    要匹配所有内容,请将规则更改为:

    RewriteRule .* public/index.php [L]
    

    .* 表示“零个或多个字符”,它确实匹配空字符串。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-23
      • 2017-05-22
      相关资源
      最近更新 更多