0
我有一個小問題:htaccess的 - 類別/子/頁
我的URL:本地主機/ CAT /類別/子/頁
示例:本地主機/ CAT /電影/ 3D/7
守則:
RewriteRule ^([a-z0-9\-]+)/([a-z0-9\-]+)/?$ $1.php?wq=$2 [NC,L] ## wq is Category
RewriteRule ^([a-z0-9\-]+)/([a-z0-9\-]+)/([a-z0-9\-]+)/?$ $1.php?wq=$2&wsq=$3 [NC,L] ## wsq is Subcategory/but if no Subcategory and Pagination -> False it must be "&wpq="
RewriteRule ^([a-z0-9\-]+)/([a-z0-9\-]+)/([a-z0-9\-]+)/([a-z0-9\-]+)/?$ $1.php?wq=$2&wsq=$3&wpq=$4 [NC,L] ## wpq is Pagination
我目前的htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z0-9\-]+)/?$ $1.php [NC,L]
RewriteRule ^([a-z0-9\-]+)/([a-z0-9\-]+)/?$ $1.php?wq=$2 [NC,L] ## wq is Category
RewriteRule ^([a-z0-9\-]+)/([a-z0-9\-]+)/([a-z0-9\-]+)/?$ $1.php?wq=$2&wsq=$3 [NC,L] ## wsq is Subcategory/but if no Subcategory and Pagination -> False it must be "&wpq="
RewriteRule ^([a-z0-9\-]+)/([a-z0-9\-]+)/([a-z0-9\-]+)/([a-z0-9\-]+)/?$ $1.php?wq=$2&wsq=$3&wpq=$4 [NC,L] ## wpq is Pagination
RewriteCond %{REQUEST_METHOD} !POST [NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule^%1 [R,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([\w.-]+)/?$ $1.php [L]
這應該儘可能,只有問題,如果只有一個類別(沒有子卡)被輸入,那麼應該檢查參數2是否只有數字。
如果只輸入數字,那麼它不是一個子類別,但分頁參數(然後第二個參數必須是「wsq」而不是「wsq」)。
我希望你明白我的意思是:d
這可以用PHP來完成,但我認爲通過的.htaccess是更好?
預先感謝您的時間。
謝謝你,它的偉大工程;) 但是,如果我有一個網址都是這個:http://本地主機/ CAT/WQ = filme 它不重寫到http://本地主機/ CAT/filme?/ RewriteRule ^([a-z0-9 \ - ] +)/([a-z0-9 \ - ] +)/?$ $ 1.php?wq = $ 2 [NC,L] – playnic
不確定明白:如果你想'/ cat /?wq = filme'在'/ cat/filme'上重定向,你目前沒有規則可以這麼做。 – julp