2014-03-05 17 views
1

好吧,我有重寫規則,在我的.htaccess如何把%或其他任何重寫規則在.htaccess

RewriteRule ^([a-z]+)/?([a-zA-Z0-9+_-]+)?,?((\d+))?/?((\d+))?/?$ index.php?page=$1&id=$2&cat=$3&view=$5 [QSA,L] 

所以,如果我有網頁是這樣的:/搜索/搜索+字,5/2 theres沒有問題...

但如果我有這樣的頁面:/search/%EA%EE%F2%EA%E8,5/2 theres一個問題。我不能在我的搜索表單中使用西里爾文的單詞。我嘗試在RewriteRule中放入%或\%或^%,但沒有運氣:(我嘗試使用更多符號,並將其替換爲索引中的%,但仍然不起作用。

有人能告訴我如何對我來說這重寫規則與%工作太(或與另一個符號,我可以使用)

編輯:

這個規則:

RewriteRule ^([a-z]+)/?([^,]+)?,?((\d+))?/?((\d+))?/?$ index.php?page=$1&id=$2&cat=$3&view=$5 [QSA,L,B] 

的答案是:

sitename.com/ -> Page:index; ID:.php; CAT:; VIEW:; <- ERROR: must be page="" and ID="" 

sitename.com/home/ -> Page:home; ID:; CAT:; VIEW:; 

sitename.com/video/152 -> Page:video; ID:152; CAT:; VIEW:; 

sitename.com/video/0/3/ -> Page:video; ID:0/3; CAT:; VIEW:; <- ERROR: must be VIEW=3 

sitename.com/search/ -> Page:search; ID:; CAT:; VIEW:; 

sitename.com/search/search+word/ -> Page:search; ID:search+word/; CAT:; VIEW:; <- Its OK... but still don't want this/in the id query 

sitename.com/search/search+word,2/ -> Page:search; ID:search+word; CAT:2; VIEW:; 

sitename.com/search/search+word,2/3/ -> Page:search; ID:search+word; CAT:2; VIEW:3; 

回答

1

您可以使用此規則:

RewriteCond %{REQUEST_FILENAME} -d [OR] 
## If the request is for a valid file 
RewriteCond %{REQUEST_FILENAME} -f [OR] 
## If the request is for a valid link 
RewriteCond %{REQUEST_FILENAME} -l 
## don't do anything 
RewriteRule^- [L] 

RewriteRule ^([a-z]+)/([^,]+),(\d+)/(\d+)/?$ index.php?page=$1&id=$2&cat=$3&view=$4 [NC,QSA,L,B] 
RewriteRule ^([a-z]+)/([^,/]+)/(\d+)/?$ index.php?page=$1&id=$2&view=$3 [NC,QSA,L,B] 
RewriteRule ^([a-z]+)/([^,/]+)/?$ index.php?page=$1&id=$2 [NC,QSA,L,B] 
RewriteRule ^([a-z]+)/?$ index.php?page=$1 [NC,QSA,L,B] 
+0

都能跟得上......它仍然不工作:/ 未找到 所請求的URL /搜索/êîòêè,2/3 /未找到在這臺服務器上。 – Nicox

+0

試試這個:'RewriteRule ^([az] +)/([^,] +),(\ d +)/(\ d +)/?$ index.php?page = $ 1&id = $ 2&cat = $ 3&view = $ 4 [QSA,L,B]' – anubhava

+0

現在,它的工作!謝謝:-) 如何點擊標記第二個答案爲接受? – Nicox