Cleaning up nested mod_rewrite statements

坚强是说给别人听的谎言 提交于 2019-12-30 10:18:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!