useful .htaccess hack for redirecting all requests to the same URL

Not terribly exciting, but I lost this bit of code once, so I’m making an archive.

This is useful if you want to redirect http://tylerwillis.com to http://www.tylerwillis.com without going through any needless meta refreshing or webpage crap. Stick this in your .htaccess and all requests will automatically be forwarded instantaneously.

Why?

Better to have just one URL than two for pagerank and adsense tracking. Also makes things nice and uniform. For the anal, I guess.

In any case, ripped straight from my file:

# BEGIN Redirect to www
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^tylerwillis\.com [NC]
RewriteRule ^/*(.*) http://www.tylerwillis.com/$1 [L,R=301]
# END Redirect to www

Simply change tylerwillis with whatever domain you need.

Source is a thread over at webhosting talk.

One Response to 'useful .htaccess hack for redirecting all requests to the same URL'

  • a gravatar 1
    On February 5th, 2008 at 3:58 pm - 2 years after having consummated a rendezvous - a scurvy gunman of doom, having made 1 unconsidered decrees precedently, swinging the moldy Internet Explorer 7.0 on Windows XP and whose name must not be spoken testUser, alleged:

    alert(’this is a test’);

    [Quote]

Leave a Response

149 MYSQL queries. Creative Commons License Loaded in 3.904 seconds.