Hey,
I'd like to configure my site to redirect to http://example.com when http://www.example.com is accessed.. How is this accomplished? I have control of subdomains and the DNS zone, but not the server config itself.
Thanks!![]()
| SitePoint Sponsor |
Hey,
I'd like to configure my site to redirect to http://example.com when http://www.example.com is accessed.. How is this accomplished? I have control of subdomains and the DNS zone, but not the server config itself.
Thanks!![]()
Set up a forwarder for www.example.com to http://example.com in the domain configuration menu. You shouldnt need to alter dns zones etc just adding a forwarder ... (a CNAME) even.
Yeah, that's exactly what I want to do, but I don't know how. What domain configuration menu are you talking about? I have access to CPanel and WHM... I have little experience in this, so please have patience with meOriginally Posted by Chazzy
Edit: Also, I need to use a method that Google doesn't penalize...





hmm, well, www.example.com is usually CNAME to example.com. To the end user it works as the same but in fact it is just an "alias" of the real domain.
Is there any special reason you would not want users to view the site with the www. before?
Anyhow, if so, you could propably create a index.php file or something that looks like this:
I'm not quite sure how this headers work though. I always though you only needed to send the new URI and the browser would redirect automatically and then you wouldn't need the Location header. Anyone that knows that and is willing to share his knowledge?PHP Code:<?php
header('HTTP/1.1 301 Moved·Permanently');
header('Location: http://example.com/');
header('Connection: close');
header('Content-Type: text/html; charset=iso-8859-1');
?>
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="http://example.com/">here</a>.</p>
</body></html>
Edit:
Solved, the URI header isn't sent (at least apache doesn't). Location is therefore the only header that "moves" ther user. Script changed accordingly...
- website
I simply want to make the address shorter, and personally I feel that www is getting a bit oldOriginally Posted by website
I would like it to work like http://www.wordpress.org/ does for example, where you're redirected(or forwarded?) to the unprefixed address.
Yeah, I thought about that, but www.example.com and example.com point to the same directory, and using the above as an index file, would start a never ending loop... I've tried to actually create a subdomain called "www", and then stick a file like that in that directory, but I couldn't create the subdomain, it was reserved or something like that. I tried removing the CNAME in the DNS zone first and all, but it didn't work(put it back in btw). I really don't know much about this stuff.Originally Posted by website





hmm, I noticed that www.wordpress.org uses exactly that method, or at least, they send the headers I showed as edited above. They propably don't use a .php file to output it though.
I recon there is something in the Apache settings (eg virtualhost) that tells it to redirect all users to the domain without the www. I don't know how that is done though...
- website
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^.*$ http://example.com%{REQUEST_URI} [R=301,L]
Place it inside an .htaccess or inside the VirtualHost of example.com (The VirtualHost is approach is better, but you should restart apache then)
![]()
Thanks a lot, pippo! I have no possibility to restart Apache, or change the configs, but .htaccess did the job nicely.Originally Posted by pippo
If anybody has any idea on how to do this by playing with the DNS zone or something like that, please tell, because even if mod_rewrite works fine, it's maybe not the *optimal* solution?
Thanks again, ciao![]()
Bookmarks