如何将每个请求重定向到index.php? 我还想将前5个参数作为获取值。
等。 / foo / bar / melon / car / berry /会请求index.php /?one = foo& two = bar& three = melon& four = car& five = berry(如果只有/ foo / bar /三,四和五会是空的等等。)
这可能吗?如何?
答案 0 :(得分:1)
您可以在DOCUMENT_ROOT/.htaccess
文件中使用此代码:
RewriteEngine On
RewriteBase /
# skip all files and directories from rewrite rules below
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^([^/]+)/?$ index.php?one=$1 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?one=$1&two=$2 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ index.php?one=$1&two=$2&three=$3 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ index.php?one=$1&two=$2&three=$3&four=$4 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ index.php?one=$1&two=$2&three=$3&four=$4&five=$5 [L,QSA]