1

我必須寫一個htaccess的重寫鏈接如下,也是404個 錯誤頁面到我的網站根目錄的重定向(主頁)Apache的.htaccess的重寫規則

www.example.com/index.php?page=find&name=detail&id=109&cid=8 
www.example.com/index.php?page=find&name=detail&id=109 
www.example.com/index.php?page=find&name=detail 
www.example.com/index.php?page=find 

應該重寫

www.example.com/find/name/detail/id/109/cid/8 
www.example.com/find/name/detail/id/109 
www.example.com/find/name/detail 
www.example.com/find 
+0

如果URL是'www.example.com/foobar'應該是導致404或'www.example.com/index.php頁= foobar'? – anubhava 2014-09-26 14:08:14

回答

0

你的htaccess的規則,

<IfModule mod_rewrite.c> 
Options +FollowSymLinks 
RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php?file=$1 [L,QSA] 
RewriteRule ^([a-zA-Z]+)/page/([a-zA-Z]+)/id/([0-9]+)/cid/([0-9]+)/$ index.php?page=find&name=detail&id=109&cid=8 [L] 
RewriteRule ^([a-zA-Z]+)/page/([a-zA-Z]+)/id/([0-9]+)/$ index.php?page=find&name=detail&id=109 [L] 
RewriteRule ^([a-zA-Z]+)/page/([a-zA-Z]+)/$ index.php?page=find&name=detail [L] 
RewriteRule ^([a-zA-Z]+)/$ index.php?page=find [L] 
</IfModule> 
+0

非常感謝,但我也希望page,id,cid這些也可以作爲一個變量。而404錯誤重定向到我的主頁。 – 2014-09-26 13:36:07

0

嘗試:

RewriteEngine On 
RewriteRule ^find$ index.php?page=find [L,QSA] 
RewriteRule ^(find)/([^/]+)/([^/]+)(.*)$ /$1$4?$2=$3 [L,QSA] 
FallbackResource/
0

試試這個代碼:

RewriteCond %{SCRIPT_FILENAME} !-d 
RewriteCond %{SCRIPT_FILENAME} !-f 
RewriteRule (.*)/([a-zA-z0-9]*)/(.*)/([a-zA-z0-9]*)/(.*)/([a-zA-z0-9]*)/(.*)/([a-zA-z0-9]*)/(.*)\.html index.php?itfpage=$1&$2=$3&$4=$5&$6=$7$8=$9 [L] 
RewriteRule (.*)/([a-zA-z0-9]*)/(.*)/([a-zA-z0-9]*)/(.*)/([a-zA-z0-9]*)/(.*)\.html index.php?itfpage=$1&$2=$3&$4=$5&$6=$7 [L] 
RewriteRule (.*)/([a-zA-z0-9]*)/(.*)/([a-zA-z0-9]*)/(.*)\.html index.php?itfpage=$1&$2=$3&$4=$5 [L] 
RewriteRule (.*)/([a-zA-Z]*)/(.*)\.html index.php?itfpage=$1&$2=$3 [L]