+ Post New Thread
Results 1 to 8 of 8
Web Development Thread, Redirecting from WWW. in Coding and Web Development; Hi guys, Wondering if anyone knows of a way to redirect a domain name from http://www.yourdomain.com to just http://yourdomain.com I'm ...
  1. #1

    Join Date
    Jan 2008
    Location
    UK
    Posts
    78
    Thank Post
    5
    Thanked 6 Times in 6 Posts
    Rep Power
    15

    Redirecting from WWW.

    Hi guys,

    Wondering if anyone knows of a way to redirect a domain name from http://www.yourdomain.com to just http://yourdomain.com

    I'm pretty sure there's a way to go from http://yourdomain.com to http://www.yourdomain.com using mod_rewrite (or is it just a redirect in .htaccess?)

    Gah, I'm not sure.

    If anyone has any idea how to achieve this with apache that'd be great.

    I'm planning on making my own version of tinyurl.com - just as a bit of fun really, and it'd be nice to make sure the domain is a short is possible, preferably without the www.

    Cheers,
    Tom.

  2. #2

    Join Date
    Feb 2009
    Posts
    45
    Thank Post
    1
    Thanked 5 Times in 5 Posts
    Rep Power
    12
    Can't you just do that with a CName entry in your DNS configuration ??

    There may be issues with what you've actually registered tho'

  3. #3

    webman's Avatar
    Join Date
    Nov 2005
    Location
    North East England
    Posts
    8,406
    Thank Post
    639
    Thanked 961 Times in 661 Posts
    Blog Entries
    2
    Rep Power
    324
    This should do it:

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

  4. Thanks to webman from:

    tomdawson (28th February 2009)

  5. #4

    Join Date
    Jan 2008
    Location
    UK
    Posts
    78
    Thank Post
    5
    Thanked 6 Times in 6 Posts
    Rep Power
    15
    I'm using a shared hosting company for now, it's just easier.

    They always auto-configure every domain to have thedomain.com and WWW.thedomain.com pointing to the webspace.

    Besides I don't see how I could redirect a CNAME, surely is just points at the IP address or another CNAME, it won't actually do any redirecting.

    I'd like the URL to actually change. When someone accesses http://www.thisdomain.com I want it to redirect to http://thisdomain.com so that it's nice and short when people copy the address.

  6. #5

    Join Date
    Jan 2008
    Location
    UK
    Posts
    78
    Thank Post
    5
    Thanked 6 Times in 6 Posts
    Rep Power
    15
    Quote Originally Posted by webman View Post
    This should do it:

    Code:
    RewriteEngine On 
    RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
    RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
    Gah, posted again just after you'd replied, webman.

    Spot on, you're a star

    I knew it could be done, just not sure about the exact code for the .htaccess file.

    Thankyou!

  7. #6
    kesomir's Avatar
    Join Date
    Mar 2008
    Location
    London
    Posts
    288
    Thank Post
    15
    Thanked 28 Times in 23 Posts
    Rep Power
    18
    It's considerably faster / lower overhead to put the rewrite code in the httpd.conf file rather than using .htacess files (unless this isn't an option ofv)

    http://httpd.apache.org/docs/1.3/howto/htaccess.html

  8. #7

    Join Date
    Jan 2008
    Location
    UK
    Posts
    78
    Thank Post
    5
    Thanked 6 Times in 6 Posts
    Rep Power
    15
    Quote Originally Posted by kesomir View Post
    It's considerably faster / lower overhead to put the rewrite code in the httpd.conf file rather than using .htacess files (unless this isn't an option ofv)

    Apache Tutorial: .htaccess files
    Definitely, and I have before, but again I'm planning to run this on shared hosting at the moment so .htaccess is my only choice. Good spot though

  9. #8

    Join Date
    Feb 2009
    Location
    Manchester
    Posts
    44
    Thank Post
    14
    Thanked 5 Times in 5 Posts
    Rep Power
    12
    This is good practice for all websites - it amazes me how many bring up a 404 (or, even worse, admin login screens) when you omit a www, and less literate users are likely to just assume that the site is down or doesn't exist.

SHARE:
+ Post New Thread

Similar Threads

  1. Redirecting desktop
    By chrbb in forum How do you do....it?
    Replies: 9
    Last Post: 17th November 2010, 02:30 PM
  2. redirecting desktop
    By Jamie_a in forum Windows
    Replies: 2
    Last Post: 15th January 2008, 01:22 PM
  3. Redirecting My Documents
    By faza in forum Wireless Networks
    Replies: 6
    Last Post: 21st December 2007, 02:24 PM
  4. redirecting my documents
    By chrbb in forum Wireless Networks
    Replies: 7
    Last Post: 7th November 2007, 01:55 AM
  5. Redirecting My documents
    By faza in forum Wireless Networks
    Replies: 15
    Last Post: 9th October 2007, 01:17 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •