以下是我的.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
答案 0 :(得分: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
答案 1 :(得分: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