重写规则不起作用htaccess

时间:2013-09-07 20:54:23

标签: php .htaccess mod-rewrite get rewrite

我有以下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 

就在我尝试使用其他人时,只传递了名称获取变量,而不是

$_GET['season']

$_GET['episode']

我知道这很简单,我很遗憾或者已经完成了,但我似乎无法让它发挥作用。

2 个答案:

答案 0 :(得分:2)

尝试一下:

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

答案 1 :(得分:1)

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

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