1

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

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

4

2 回答 2

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
于 2013-09-08T15:02:02.587 回答
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
于 2013-09-07T21:12:10.830 回答