tomdawson Posted February 28, 2009 Posted February 28, 2009 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.
mrwITch Posted February 28, 2009 Posted February 28, 2009 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'
webman Posted February 28, 2009 Posted February 28, 2009 This should do it: RewriteEngine On RewriteCond %{HTTP_HOST} ^www.example.com$ [NC] RewriteRule ^(.*)$ http://example.com/$1 [R=301,L] 1
tomdawson Posted February 28, 2009 Author Posted February 28, 2009 I'm using a shared hosting company for now, it's just easier. They always auto-configure every domain to have thedomain.com and http://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.
tomdawson Posted February 28, 2009 Author Posted February 28, 2009 This should do it: 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!
kesomir Posted February 28, 2009 Posted February 28, 2009 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
tomdawson Posted February 28, 2009 Author Posted February 28, 2009 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
fernt Posted March 2, 2009 Posted March 2, 2009 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.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now