URL Rewriting
URL Rewriting with .htaccess
A quick guide to URL Rewriting
#Start URL Rewriting
Options +FollowSymLinks
RewriteEngine on
#This will rewrite all non-www urls with www
# ie http://example.com will be rewritten as http://www.example.com
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
#This statement ReDirects all urls with trailing / to urls without trailing slash
RewriteRule ^([_a-zA-Z0-9-]+)/+$ /$1 [R]
#This statement ReWrites all urls of the form http://www.example.com/?blog.php?ID=xx as http://www.example.com/xx
RewriteRule ^([_a-zA-Z0-9-]+)+$ [...]
htaccess cheat sheet
1. Rewrite All URLs on one domain to new domain
Put the following code in the .htaccess file of your old domain
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]
2. Rewrite non-www urls with www
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]








