Clearing nested mod_rewrite statements

I am cleaning a large .htaccess file containing many mod_rewrite statements.

Most of the confusion comes from claims spanning various occurrences.

 /directory1 /directory1/directory2 /directory1/directory2/directory3 

using expressions 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 anyone get to know mod_rewrite give me a pointer to how to write one universal statement that will catch any depth of directory1/directory2... and put the corresponding level variable in a RewriteRule?

+4
source share
1 answer

Rather use the following rewrite

 RewriteRule ^(.*)$ front.php/$1 [L] 

and access folders by pathinfo in front.php :

 $pathinfo = $_SERVER['PATH_INFO']; 

Alternatively, you can also enable MultiViews in Apache and configure it instead of front.php as an index file and get the path along the same way.

+2
source

Source: https://habr.com/ru/post/1300574/


All Articles