Forum Moderators: phranque
I want to rewrite my url like [host.com...] to [host.com...] Ive read about recursive mode with [N] key for RewriteRule, but I couldn't use it well.
Ive tried following code in my .htaccess file:
RewriteEngine On
RewriteOptions MaxRedirects=20
RewriteCond %{REQUEST_URI} ^(.*)/([^/]+)/([^/]+)/(.*)$
RewriteRule ^.*$ /class.%2.php?action=someaction&item[]=%3&lang=%1 [NC,N]
... (2) [per-dir y:/home/unistrict.ru/www/] rewrite ru/services/distribution/ -> /class.services.php?action=someaction&item[]=distribution&lang=/ru
... (2) [per-dir y:/home/unistrict.ru/www/] rewrite /class.services.php/services/distribution/ -> /class.services.php?action=someaction&item[]=distribution&lang=/ru
... (2) [per-dir y:/home/unistrict.ru/www/] rewrite /class.services.php/services/distribution/ -> /class.services.php?action=someaction&item[]=distribution&lang=/ru
... (2) [per-dir y:/home/unistrict.ru/www/] rewrite /class.services.php/services/distribution/ -> /class.services.php?action=someaction&item[]=distribution&lang=/ru
If the number of parameters is less than 10, then I'd suggest a series of rules, each designed to extract one parameter from the input URL.
If the number of parameters is greater than nine, then I'd suggest rewriting all appropriate requests directly to the script, and modifying the script itself to extract the parameters from server variable Request_URI.
Another possible solution, on Apache 2.0 and above, is to use AcceptPathInfo, and modify the script so that it gets the parameters from server variable Path_Info.
In your code, the back-reference is to %2; If you use [N], then you'll need to modify the URL, removing that part referred to by %2, so that the next step sees the proper variable in that %2 position.
Also, using ^.*/<specific_pattern/.*$ will be prone to problems, because the first ".*" will 'consume' as much of the URL as possible, leaving the final .* subpattern to 'starve' -- it will likely always be blank. This will also result in the input URL being processed as if it were right-justified -- In simple terms, this pattern will prefer to go all the way to the right end of the URL, and URL-parts from the beginning of the URL will be preferentially dropped. Sorry for the complex wording, but I can't think of a better way to put it. I strongly suggest using one the approaches above.
Jim