I have just finished writing a new site. It is a simple blog. The only advice I have received from my readers is that I should consider changing the www.example.com/?page=3 to something like www.example.com/1.
How should I go about writing this rewrite rule?
If your URLs have a common pattern and parts of the externally used URL can directly be mapped onto the internally used URL while retaining a uniquely identifiable URL (like your URL probably does), you can do something like this with mod_rewrite:
RewriteEngine on RewriteRule ^[0-9]+$ /?page=$1 [L,QSA]
This will rewrite a request of
/12345 internally to
Otherwise, if there isn’t a pattern or the mapping is not trivial, you will probably need to specify each case like:
RewriteEngin on RewriteRule ^foo$ /?page=1 [L,QSA] RewriteRule ^bar$ /?page=2 [L,QSA] RewriteRule ^baz$ /?page=3 [L,QSA]
You could also just pass the request to your PHP file and do the mapping in there.