g1smd - 1:36 am on Jul 17, 2010 (gmt 0)
The bit on the left, the pattern, is matched against the GET request sent by the browser.
The server then either
- sends a redirect header back to the browser and the details of a new URL for the browser to use to make a new request for that new URL; or,
- internally rewrites the request to silently fetch the content from a different location inside the server.
So, in the case of a rewrite, the user sees in their URL bar the URL contained in the href of the link they clicked on. The browser asks for that URL, and the server serves some content. The URL seen in the URL bar does not change.
Rewrites do not "make" URLs. URLs are defined in links. A rewrite tranlates a URL request into an internal server filepath to fetch the required content from.
The code above has a redirect and a rewrite. The redirect has [R=301,L] and the rewrite just [L]. The redirect target is a URL with domain name and path. The rewrite target is purely an internal server path with attached parameters.
1. website page contains link pointing to www.example.com/somepage. User clicks link. Browser requests "GET /somepage HTTP/1.1" from www.example.com server. Server processes rewrite to fetch content from /folder/index.php?page=somepage inside the server.
2. Searchengine results page contains link to old www.example.com/folder/index.php?page=somepage URL. User clicks link. Browser requests "GET /folder/index.php?page=somepage HTTP/1.1" from www.example.com server. Server processes request and generates 301 header and sends it to browser, and also generates "Location: www.example.com/somepage" header and sends it to the browser. Browser makes new request for "GET /somepage HTTP/1.1" and server responds exactly as detailed in step 1 above.
To be clear, Mod_Rewrite does not "make" URLs. It deals with requests coming into the server from the outside world. It then either tells the outside world to go make a different request for another URL (a redirect), or else it goes off and finds the content from inside the server but at a different internal location to that suggested by the path part of the incoming URL request (a rewrite).
It is the internal path pointer that is rewritten. For users to use new URLs, those are the URLs you need to link to in the pages of your site.
The (.*) is problematical. It matches the entire input, and then has to back-off-and-retry multiple times in an attempt to find a match. The initial match was "too greedy". Replacing it with ([^.]+) or similar will parse much faster.