2014-01-17 46 views
0

以下是我的.htaccess文件。。5個變量的htaccess問題

AddDefaultCharset utf-8 
RewriteEngine On 

RewriteCond %{REQUEST_FILENAME} -f 
RewriteRule .* - [L] 

DirectoryIndex index.php 
RewriteRule ^([a-zA-Z0-9_-]{3,20})/([^/]+)/([^/]+)?$ index\.php?page=$1&s=$2&o=$3&p=$4&q=$5 [L] 

RewriteRule ^([a-zA-Z0-9_-]{3,20})/([^/]+)/([^/]+)?$ index\.php?page=$1&s=$2&o=$3&p=$4 [L] 

RewriteRule ^([a-zA-Z0-9_-]{3,20})/([^/]+)/([^/]+)?$ index\.php?page=$1&s=$2&o=$3 [L] 

RewriteRule ^([a-zA-Z0-9_-]{3,20})/([^/]+)?$ index\.php?page=$1&s=$2 [L] 

RewriteRule ^([a-zA-Z0-9_-]{3,20})/?$ index\.php?page=$1 [L] 

RewriteRule ^([a-zA-Z0-9_-]{3,20})?$ index\.php?page=$1 [L] 

ErrorDocument 404 /404 

當我這樣做

ehco "<pre>"; 
print_r($_REQUEST); 
echo "</pre>"; 

有3個參數,它顯示我

Array 
(
    [page] => test 
    [s] => 1 
    [o] => 9 
    [p] => 
    [q] => 
) 

但如果超過3個參數,它說沒有找到。 的.htaccess在以下網址做工精細 爲myhost/mysite的/網頁/ S/O 而不是 爲myhost /頁/ S/O/P

回答

1

你的代碼的一些變化:

AddDefaultCharset utf-8 
RewriteEngine On 

RewriteCond %{REQUEST_FILENAME} -f 
RewriteRule .* - [L] 

DirectoryIndex index.php 
RewriteRule ^([a-zA-Z0-9_-]{3,20})/([^/]+)/([^/]+)/([^/]+)/([^/]+)?$ index\.php?page=$1&s=$2&o=$3&p=$4&q=$5 [L] 

RewriteRule ^([a-zA-Z0-9_-]{3,20})/([^/]+)/([^/]+)/([^/]+)?$ index\.php?page=$1&s=$2&o=$3&p=$4 [L] 

RewriteRule ^([a-zA-Z0-9_-]{3,20})/([^/]+)/([^/]+)?$ index\.php?page=$1&s=$2&o=$3 [L] 

RewriteRule ^([a-zA-Z0-9_-]{3,20})/([^/]+)?$ index\.php?page=$1&s=$2 [L] 

RewriteRule ^([a-zA-Z0-9_-]{3,20})/?$ index\.php?page=$1 [L] 

RewriteRule ^([a-zA-Z0-9_-]{3,20})?$ index\.php?page=$1 [L] 

ErrorDocument 404 /404 
+0

你的意思是下面添加這些第3行e第一重寫規則? – baig772

+0

編輯,現在列出的洞代碼 –

+0

耶謝謝,它工作:) – baig772

0

你正確的完整的.htaccess可以這樣:

AddDefaultCharset utf-8 
RewriteEngine On 

RewriteCond %{REQUEST_FILENAME} -f [OR] 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule^- [L] 

DirectoryIndex index.php 

RewriteRule ^(\w{3,20})/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ index\.php?page=$1&s=$2&o=$3&p=$4&q=$5 [QSA,L] 

RewriteRule ^(\w{3,20})/([^/]+)/([^/]+)/([^/]+)/?$ index\.php?page=$1&s=$2&o=$3&p=$4 [QSA,L] 

RewriteRule ^(\w{3,20})/([^/]+)/([^/]+)/?$ index\.php?page=$1&s=$2&o=$3 [QSA,L] 

RewriteRule ^(\w{3,20})/([^/]+)/?$ index\.php?page=$1&s=$2 [QSA,L] 

RewriteRule ^(\w{3,20})/?$ index\.php?page=$1 [QSA,L] 

ErrorDocument 404 /404