【问题标题】:mod_rewrite : why does it work locally and not online?mod_rewrite :为什么它在本地工作而不是在线工作?
【发布时间】:2010-10-23 00:06:49
【问题描述】:

我正在本地开发应用程序(在域名 .dev 下)。

为了使用友好的 url,我已经像这样设置了我的 .htaccess:

RewriteEngine on
# Externally redirect to add missing trailing slash
RewriteRule ^(([a-z0-9._\-]+/)*[a-z0-9_\-]+)$ http://example.com/$1/?%{QUERY_STRING}[NC,R,L]
RewriteRule ^about/$ about.php [NC,L]
RewriteRule ^issues/$ issues.php [NC,L]
RewriteRule ^issue/([a-z0-9_\-]+)/$ issue.php?slug=$1 [NC,L]

SetEnv PHP_VER 5
IndexIgnore *
Options +FollowSymLinks

它工作正常。烦人的是,上网的时候就不是那么好了:

http://example.com/issue/my-slug/#23 不返回 GET 变量。为什么?

【问题讨论】:

标签: .htaccess mod-rewrite friendly-url


【解决方案1】:

根据过去的经验,我的猜测是 RewriteBase,可能是因为您在共享服务器上,或者其他一些非标准配置。

RewriteEngine on

#Set base as doc root.
RewriteBase /

# Externally redirect to add missing trailing slash
RewriteRule ^(([a-z0-9._\-]+/)*[a-z0-9_\-]+)$ http://mydomain.eu/$1/?%{QUERY_STRING}[NC,R,L]
RewriteRule ^about/$ about.php [NC,L]
RewriteRule ^issues/$ issues.php [NC,L]
RewriteRule ^issue/([a-z0-9_\-]+)/$ issue.php?slug=$1 [NC,L]

SetEnv PHP_VER 5
IndexIgnore *
Options +FollowSymLinks

【讨论】:

    【解决方案2】:

    我没看到

    RewriteRule ^(([a-z0-9._\-]+/)*[a-z0-9_\-]+)$ http://mydomain.eu/$1/?%{QUERY_STRING}[NC,R,L]
    

    应该匹配那个 URL,但那是唯一一个带有 [R] 标志来进行外部重定向的 URL。尝试注释掉该行,以确保应用程序的其他部分没有执行重定向。我的猜测是有。

    【讨论】:

      【解决方案3】:

      替换 URL 和标志之间缺少一些空格。您还可以将您的第一条规则简化如下:

      RewriteRule ^([a-z0-9._-]+/)*[a-z0-9_-]+$ %{REQUEST_URI}/ [NC,R=301,L]
      

      【讨论】:

        猜你喜欢
        • 2020-06-15
        • 1970-01-01
        • 1970-01-01
        • 2013-01-10
        • 2017-11-12
        • 2022-10-02
        • 1970-01-01
        • 1970-01-01
        • 2012-06-18
        相关资源
        最近更新 更多