Sponsor: MP3 music download

Thursday, July 29, 2004

Handy mod_rewrite rule

I've been using mod_rewrite a lot lately, but never really got the hang of using environment variables with it (maybe I've never needed too...).

Anyway, I run several sites where we have the .com, .co.uk, and often the .org domains. Several of these are hosted on my business server, and the guy who runs this always sets them up so requests to any domain always end up at the primary domain.

E.g.

http://www.example.co.uk/foo.html

goes to

http://www.example.com/foo.html

This is great. However, I have recently started using a certain web hosting company for several sites (they're a very good company), but when I own multiple versions of one domain the requests don't get re-directed as I like: they just work under the other domain.

This cunning mod_rewrite rule will fix that for you:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.example\.co\.uk$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]


Useful stuff :-)

19 Comments:

  • The mod_rewrite is also what is used to rewrite variables in a URL no so? for instance.

    http://www.site.com/index.php?cat=1&sub=2&com=3 would in turn look something like

    http://www.site.com/cat/1/sub/2/com/3

    or somethning to that effect?

    By Blogger Ox, at 29 July 2004 21:02  

  • Sure. Usually it works the other way. You would turn the request:

    http://www.example.com/catalogue/item-1.html

    into a server-side request that may look like:

    http://www.example.com/cgi-bin/catalogue.cgi?item=1

    Very useful stuff, I have to say. It's great for making dynamic sites search engine friendly too :-)

    By Blogger Bokeh, at 29 July 2004 22:07  

  • I thnk im going to have to do some reading on this, could be rather usefull, and you are definitely right about the search engine rankings

    *starts to read about mod_rewrite*

    By Blogger Ox, at 31 July 2004 07:43  

  • Smart webmasters from around the world are moving their sites to ThirdSphere every single day...webhosting domain

    By Blogger St Louis Cardinals BUFF, at 4 October 2005 02:07  

  • Looking forward to reading more great info on your blog, I added you to my favorites and will be checking back often.

    My site is about professional web hosting

    If you have an interest in professional web hosting I would love to hear what you think of my site.

    By Anonymous Anonymous, at 8 October 2005 01:50  

  • Hey, you have a great blog here! I'm definitely going to bookmark you!
    I have a **WEB HOSTING** site/. It pretty much covers WEB HOSTING related stuff.
    Come and check it out if you get time :-)

    By Anonymous Anonymous, at 10 October 2005 07:42  

  • Hey, you have a great blog here!

    I have a domain free hosting web site. It pretty much covers ##WEB HOSTING## related stuff.

    We have business and personal web hosting packages. No setup fees. Low cost domain registration, SSL certificates, merchant accounts and web design.

    Come and check it out if you get time.

    By Anonymous Anonymous, at 10 October 2005 18:43  

  • Hey, you have a great blog here!
    I'm definitely going to be checking back on your blog.

    I have a reliable web hosting site. It pretty much covers ##WEB HOSTING## related stuff.

    Come and check it out if you get time.

    By Anonymous Anonymous, at 11 October 2005 19:49  

  • Yo, This blog is pretty neat. You should check out mine sometime. It pretty much covers asp web hosting related stuff.

    By Anonymous Anonymous, at 19 October 2005 16:07  

  • I enjoyed reading your blog. There is a lot of useful information about expert review seo in it. We offer Turnkey Websites and Reliable Hosting. We also provide a blogging service that will help your site get indexed fast and keep the search engines visiting your site. Click here for more information about expert review seo.
    Thank you
    TWP Admin

    By Anonymous Anonymous, at 22 October 2005 23:48  

  • Dedicated free music hosting Web Hosting Explained By: Calin Indre Why is dedicated free music hosting hosting such a big hit on the business free music hosting web hosting market? If you look at the costs it involves, usually ranging from $150 - $1000 per...

    By Anonymous Anonymous, at 23 October 2005 01:47  

  • Hey, you have a great blog here! I'm definitely going to bookmark you!

    I have a web hosting company site/blog. It pretty much covers web hosting company related stuff.

    Come and check it out if you get time :-)

    By Anonymous Anonymous, at 24 October 2005 09:06  

  • reseller hosting package Web Hosting Ecommerce Your source for the latest in the reseller hosting package industry, reseller hosting package News, links and latest reseller hosting package developments.

    By Anonymous Anonymous, at 25 October 2005 15:50  

  • Hey, you have a great blog here! I'm definitely going to bookmark you!

    I have a domain web hosting site/blog. It pretty much covers domain web hosting related stuff.

    Come and check it out if you get time :-)

    By Blogger Infactahost.com, at 26 October 2005 02:13  

  • Hello Bokeh, I've just been playing Serious Sam 2 before getting down to do some research into cheap web hosting package; on the whole I'd rather continue playing. First place I came to was this post so I've been having a good time reading your blog. There are some ideas that I could maybe incorporate into cheap web hosting package to make it more useful. Thank you!

    By Anonymous dns hosting, at 13 November 2005 02:01  

  • Hi,

    I've put up a site related to free domain hosting its only been up a couple of days. and i'm still scouting around for information and articles that may be suitable for some of my free domain hosting pages. Your free domain hostingblog seems to be a good idea, I doubt if my free domain hosting site will become as popular... but I suppose that depends on me finding those free domain hosting articles.... A well, on with my journey - thanks for reading, hope to see you on my free domain hosting site.

    Take care
    Steward.

    By Anonymous Anonymous, at 19 November 2005 17:13  

  • Hello,

    Just thought I would check out your blog.
    I am new to blogging. I hope you don't mind me posting to your blog. If you are interested in checking out my blog and making a post that would be great.

    I have a best company hosting web site/blog. It pretty much covers ##WEB HOSTING## related stuff.


    Thanks,
    Ed

    By Anonymous Anonymous, at 22 November 2005 19:27  

  • Hi Fellow! I was just searching blogs,and I found your site! I like it!
    If you have a moment, please visit my site:
    web video hosting
    It covers web video hosting related contents.
    All the best!

    By Blogger James Baker, at 18 January 2006 05:17  

  • As a top-rated company in the world of ecommerce, Infyecommercesolution has carved out a niche for itself and with the ecommerce solution provided by the company receiving accolades from clients all over the world, it has, in the true sense of the word, grown up to be a top-notch outsourcing software development company. For details on all the services provided by the company, visit http://www.infyecommercesolution.com.

    By Anonymous ecommercewebmaster12, at 10 November 2008 05:29  

Post a Comment

<< Home