eUttaranchal

Re-Writing the Web

Archive for the ‘URL Rewriting’ Category

Canonical URL issue has always been a headache to the Webmasters and SEOs. But thanks to apache’s mod_rewrite which provide nice escapes for this problem

1. Rewrite all your urls WITHOUT www to WITH www

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^euttaranchal.com
RewriteRule (.*) http://www.yourdomain.com/$1 [R=301,L]

2. Redirect all your index.php and index.html files to homepage or directory root

Options +FollowSymLinks
RewriteEngine on

#rewrite your index.html to homepage
#eg:  http://www.yourdomain.com/index.html to http://www.yourdomain.com/

RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ http://www.yourdomain.com/$1 [R=301,L]

#rewrite your index.php to homepage
#eg: http://www.yourdomain.com/index.php to http://www.yourdomain.com/
RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ http://www.yourdomain.com/$1 [R=301,L]

** you can do this for default.html or other pages too depending on your default page name.

Popularity: 1% [?]

URL Rewriting with .htaccess

Posted by Bhupendra On January - 21 - 2008

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-]+)+$ /blog.php?ID=$1

#END URL Rewriting

Popularity: 14% [?]

htaccess cheat sheet

Posted by Bhupendra On May - 3 - 2007

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]

Popularity: 12% [?]