homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

How can I get them to be the same
www.domain.com diffrent than http://mydomain.com

 6:56 pm on Nov 10, 2003 (gmt 0)

Grr, google is thinking that my site is diffrent with www. hence ranking it 2 times. I don't want to have any problems of duplicate content or anything like that, so is there any way (on my side) to make avoid this?

As always TIA,



 12:58 am on Nov 11, 2003 (gmt 0)
JVB, try putting this in your .htaccess file in your root web site directory (if you run Apache):

RewriteEngine on
RewriteCond %{HTTP_HOST} ^yourdomain.com$
RewriteRule ^(.+) http://www.yourdomain.com/$1 [L,R=301]

Make sure you test it right away - if you mess up your .htaccess file, then getting your site can be pretty screwed up. That should make it so going to http://yourdomain.com redirects immediately and permanently to http://www.yourdomain.com/



 7:02 pm on Nov 11, 2003 (gmt 0)
Thanks Scott, that was very useful, so, if I wanted it the other way around (http://www. ---> http:// ) would it be:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.yourdomain.com$
RewriteRule ^(.+) http://yourdomain.com/$1 [L,R=301]



 7:33 pm on Nov 11, 2003 (gmt 0)

Yes, with some small corrections that apply to both versions:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.yourdomain\.com
RewriteRule ^(.*) http://yourdomain.com/$1 [L,R=301]

Ref: Introduction to mod_rewrite [webmasterworld.com]


[edited by: jdMorgan at 2:04 pm (utc) on Nov. 12, 2003]


 10:36 pm on Nov 11, 2003 (gmt 0)

Thanks jdMorgan, those corrections are right of course. Here's what they mean, in case anyone cares. (Assuming I have this right, please correct me if not, I'm just learning this stuff too):

The ^(.*) means 0 or more (*) characters of any kind (.), at the start of the line. (Rather than + which is one or more)

The \. escapes the . to mean . instead of 'any character'.

I'm not sure why the $ can't be at the end of the HTTP_HOST line, as the .com SHOULD end it - what could go after?



 11:01 pm on Nov 11, 2003 (gmt 0)

Thnx again! You guys are great :)


 11:04 pm on Nov 11, 2003 (gmt 0)


A port number is one I've had mess me up when the hostname is end-anchored. I just got in the habit of leaving it off because of that. e.g. http://www.example.com:8080



 10:11 am on Nov 12, 2003 (gmt 0)

Great advice:

<snip snip snip etc!>

<my edit: question already answered in Introduction to mod rewrite>

[edited by: superscript at 12:08 pm (utc) on Nov. 12, 2003]


 10:44 am on Nov 12, 2003 (gmt 0)


I just tried uploading this to my root directory:

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

On testing the site was down with an internal server error on both www and non-www.

Can anyone advise / see any mistakes in it?

(intention is all non-www to www)

[edited by: jdMorgan at 2:04 pm (utc) on Nov. 12, 2003]
[edit reason] De-linked [/edit]


 1:49 pm on Nov 12, 2003 (gmt 0)


Try adding

Options +FollowSymLinks

at the top of the code, before RewriteEngine on.

Some server setups need this, and some don't. If it still does not work, contact your host admin and ask them if mod_rewrite is accessible to you and whether you have sufficient priveleges to use it. At minimum, you will need AllowOverride FileInfo to use mod_rewrite. AllowOverride All is better. Only your host admin can change these AllowOverride settings.



 2:25 pm on Nov 12, 2003 (gmt 0)

> Options +FollowSymLinks

It's not in my htaccess, but all rewrites and redirects work fine, so I haven't fretted much.

I do have one curiosity on the above though. On (fairly rare) occasion, an ip rolls in attempting to access a non-existent FP extension directory, e.g., domain.tld/_vti_bin , and it gets a 403 served due to +FollowSymLinks not being present.

That doesn't seem to be a bad thang though, so I've left well enough alone. Should I be more interested than I've been to date?


 7:56 pm on Nov 12, 2003 (gmt 0)

Hi jdMorgan,

Many thanks

I've added the code as suggested - no joy - same 500 error. I've contacted my hosts, but they don't seem to understand what I'm trying to do.


 5:42 pm on Nov 26, 2003 (gmt 0)

This worked very well for me, except for one hitch. With IE, changing site.com/ to www.site.com/ causes IE to translate the "/" to "/index.php". If I try remapping index.php to /, I get a looping error :)

Any ideas?


 6:06 pm on Nov 26, 2003 (gmt 0)


That 403 means access was forbidden, so some other mechanism blocked access.


Have a look at your raw error log file to see if there is any indication of the problem there.

It sounds like your server may not support mod_rewrite.
Here's a simple test: Create an .htaccess file like this:

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^silly\.html$ /index.html [L]

"silly.html" must be a page name that does not exist on your site, and "index.html" is the name of your home page.
Now request www.yourdomain.com/silly.html with your browser, and you should see your home page.
If it doesn't work, you need to ask your hosting provider for help. If they can't help, you may need a new provider.


Welcome to WebmasterWorld [webmasterworld.com]!

Unless it's a caching issue (flush your temp files), that's probably not IE changing the path. It's most likely a config setting on the server.

What is the full name of your index page? Is it "index.html"? If so, perhaps adding this line would fix the problem:

DirectoryIndex index.html



 12:40 am on Nov 27, 2003 (gmt 0)

Thanks. I tried directoryindex (in my case it's index.php), and on a PC that's never visited the site, but no luck. And it's just with the index.php file on the root dir. I can't understand it.

Until I do, I'm just going to do a redir in PHP.


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved