>我有以下 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']
我知道这很可能是我错过或已经完成的简单事情,但我似乎无法让它工作。
试一试:
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
第一行获取所有链接,因为它匹配所有链接。
尝试颠倒顺序:
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