问题
I am cleaning up a large .htaccess
file containing a lot of mod_rewrite
statements.
The biggest part of the clutter comes from statements catching various occurrences of
/directory1
/directory1/directory2
/directory1/directory2/directory3
using statements like
RewriteCond %{REQUEST_URI} ^/([^/]+)/([^/]+)$
RewriteRule .* /front.php?level1=%1&level2=%2&%{QUERY_STRING} [L]
RewriteCond %{REQUEST_URI} ^/([^/]+)/([^/]+)/([^/]+)$
RewriteRule .* /front.php?level1=%1&level2=%2&level3=%3&%{QUERY_STRING} [L]
could somebody versed with mod_rewrite give me a pointer on how to write one universal statement that will catch any depth of directory1/directory2...
and put the appropriate level
variable into the RewriteRule?
回答1:
Rather use the following rewriterule
RewriteRule ^(.*)$ front.php/$1 [L]
and access folders by pathinfo in front.php
:
$pathinfo = $_SERVER['PATH_INFO'];
You can alternatively also enable MultiViews
in Apache and configure it to use front.php
as index file instead and grab pathinfo the same way.
来源:https://stackoverflow.com/questions/2219098/cleaning-up-nested-mod-rewrite-statements