代码之家  ›  专栏  ›  技术社区  ›  pixeline

修改:为什么它在本地工作而不是在线?

  •  0
  • pixeline  · 技术社区  · 16 年前

    我正在本地开发一个应用程序(在域名下) <myDomain>.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 返回no get变量。为什么?

    3 回复  |  直到 16 年前
        1
  •  0
  •   Eddie    15 年前

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

    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
  •  0
  •   gregmac    16 年前

    我看不出来

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

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

        3
  •  0
  •   Gumbo    15 年前

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

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