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 ...
-
28th February 2009, 02:26 PM #1
- Rep Power
- 9
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.
-
-
IDG Tech News
-
28th February 2009, 02:37 PM #2
- Rep Power
- 7
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'
-
-
28th February 2009, 02:42 PM #3 This should do it:
Code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
-
Thanks to webman from:
tomdawson (28th February 2009)
-
28th February 2009, 02:43 PM #4
- Rep Power
- 9
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.
-
-
28th February 2009, 02:46 PM #5
- Rep Power
- 9

Originally Posted by
webman
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!
-
-
28th February 2009, 04:45 PM #6 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
-
-
28th February 2009, 09:43 PM #7
- Rep Power
- 9

Originally Posted by
kesomir
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
-
-
2nd March 2009, 09:53 AM #8
- Rep Power
- 7
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:
Similar Threads
-
By chrbb in forum How do you do....it?
Replies: 9
Last Post: 17th November 2010, 03:30 PM
-
By Jamie_a in forum Windows
Replies: 2
Last Post: 15th January 2008, 02:22 PM
-
By faza in forum Networks
Replies: 6
Last Post: 21st December 2007, 03:24 PM
-
By chrbb in forum Networks
Replies: 7
Last Post: 7th November 2007, 02:55 AM
-
By faza in forum 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
-
Forum Rules