【问题标题】:Rewrite rules not working htaccess重写规则不起作用 htaccess
【发布时间】:2013-09-08 23:02:02
【问题描述】:

我有以下 htaccess 重写规则

RewriteRule ^shows-watch/(.*).html?$ show.php?name=$1 
RewriteRule ^shows-watch/(.*)/season-(.*).html?$ show.php?name=$1&season=$2
RewriteRule ^shows-watch/(.*)/season-(.*)/episode-(.*).html?$ show.php?name=$1&season=$2&episode=$3

现在问题是,第一个重写规则就可以了

RewriteRule ^shows-watch/(.*).html?$ show.php?name=$1 

只是当我尝试使用其他的时候,只有 name get 变量被传递,而不是

$_GET['season']

$_GET['episode']

我知道这很可能是我错过或做过的一些简单的事情,但我似乎无法让它发挥作用。

【问题讨论】:

    标签: php .htaccess mod-rewrite get rewrite


    【解决方案1】:

    试试这个:

    Options +FollowSymLinks -MultiViews
    
    RewriteEngine On
    RewriteBase /
    
    RewriteRule ^shows-watch/([^/]+)/season-([^/]+)/episode-([^/]+).html?$ show.php?name=$1&season=$2&episode=$3 [QSA,NC,L]
    RewriteRule ^shows-watch/([^/]+)/season-([^/]+).html?$ show.php?name=$1&season=$2 [QSA,NC,L]
    RewriteRule ^shows-watch/([^.]+)\.html?$ show.php?name=$1 [QSA,NC,L]
    

    顺序非常重要,因此它们不会重叠,您还需要L 标志在需要时停止。

    这假设您的 .htaccess 与 show.php 文件一起位于您域的根文件夹中,并且您正在像这样访问它:

    domain.com/shows-watch/Show Name.html
    domain.com/shows-watch/Show Name/season-1.html
    domain.com/shows-watch/Show Name/season-1/episode-10.html
    

    【讨论】:

      【解决方案2】:

      第一行获取所有链接,因为它匹配所有链接。
      尝试颠倒顺序:

      RewriteRule ^shows-watch/(.*)/season-(.*)/episode-(.*).html?$ show.php?name=$1&season=$2&episode=$3    
      RewriteRule ^shows-watch/(.*)/season-(.*).html?$ show.php?name=$1&season=$2
      RewriteRule ^shows-watch/(.*).html?$ show.php?name=$1 
      

      或者你可以像这样排除斜线:

      RewriteRule ^shows-watch/([^/]*).html?$ show.php?name=$1 
      RewriteRule ^shows-watch/([^/]*)/season-([^/]*).html?$ show.php?name=$1&season=$2
      RewriteRule ^shows-watch/([^/]*)/season-([^/]*)/episode-([^/]*).html?$ show.php?name=$1&season=$2&episode=$3
      

      【讨论】:

      • 不幸的是它没有任何区别
      • 再试一次,我在本地主机上测试过,效果很好。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多