簡體   English   中英

重寫規則不起作用htaccess

[英]Rewrite rules not working htaccess

我有以下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變量,而不傳遞

$_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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM