.htaccess 获取参数 index.php
.htaccess Get Parameters to index.php
如何将每个请求重定向到 index.php?
我还想要前 5 个参数作为获取值。
等/foo/bar/melon/car/berry/ 会请求 index.php/?one=foo&two=bar&three=melon&four=car&five=berry (如果只有 /foo/bar/ 三四五会是空等)
这可能吗?如何实现?
您可以在 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= [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?one=&two= [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ index.php?one=&two=&three= [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ index.php?one=&two=&three=&four= [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ index.php?one=&two=&three=&four=&five= [L,QSA]
如何将每个请求重定向到 index.php? 我还想要前 5 个参数作为获取值。
等/foo/bar/melon/car/berry/ 会请求 index.php/?one=foo&two=bar&three=melon&four=car&five=berry (如果只有 /foo/bar/ 三四五会是空等)
这可能吗?如何实现?
您可以在 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= [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?one=&two= [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ index.php?one=&two=&three= [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ index.php?one=&two=&three=&four= [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ index.php?one=&two=&three=&four=&five= [L,QSA]