Forum Moderators: phranque
?option=com_content&view=article&id=3&Itemid=36
GET /thispage?some=parameters HTTP/1.1 RewriteCond %{QUERY_STRING} ^digits=([0-9]+)&letters=([a-z]+)$
RewriteRule ^(index\.php)?$ http://www.example.com/%1-%2? [R=301,L] RewriteRule ^([0-9+])-([a-z]+) /index.php?digits=$1&letters=$2 [L] example.com/index.php?digits=123&letters=abc or for example.com/?digits=123&letters=abc to www.example.com/123-abc www.example.com/123-abc which is internally rewritten by the second rule to /index.php?digits=123&letters=abc www.example.com/index.php?digits=123&letters=abc is exposed back out on to the web as a URL and the user is redirected again in a loop. The PHP file never gets invoked. www.example.com/123-abc without parameters. THE_REQUEST is necessarily more complex. It usually begins ^[A-Z]{3,9}\ / and often ends \ HTTP/ with various other stuff in the middle to match optional index.php, e.g. /(index\.php)? followed by parameters. Rather than use \?digits=[0-9]+&letters=[a-z]+ here, the parameters part can often be generalised to \?[^\ ]+ or similar. REQUEST_URI is modified as a result of internal rewrites, THE_REQUEST is not.
Would THE_REQUEST preserve the original path moving forward to the redirects?
The difference is the %{THE_REQUEST} line, which essentially tells the server "It is OK to hand over this file, but only if the visitor didn't ask for it."
if I have a URL rewritten from a.html to b.html, the second {THE_REQUEST} should be something like GET b.html HTTP
If a URL request is rewritten, the server tries to serve the content from the rewritten internal location
So should I consider the {THE_REQUEST} and [NS] useful or perhaps ok to be used only when I'm treating everything that has not been:
a) typed in the URL address bar by a user
b) a link clicked from somewhere
RewriteCond %{THE_REQUEST} index
RewriteRule ^index\.html http://www.example.com/?redir=1 [R=301,L] RewriteCond %{THE_REQUEST} index
RewriteRule ^index\.html http://www.example.com/ [R=301,L,CO=redir:1:.example.com]
Does this mean that rewritten URL because they are not making a new request, they will keep processing the rules without the .htaccess to be parsed again from the beginning (unless the [L] won't stop processing)?
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.html\ HTTP/
RewriteRule ^(([^/]+/)*)index\.html$ http://www.example.com/$1 [R=301,L] RewiteRule ^$ /index.html [L] DirectoryIndex index.html in real life.