Forum Moderators: phranque

Message Too Old, No Replies

Redirecting example.com to www.example.com

Redirecting example.com to www.example.com

         

rajivadhy

4:20 am on Jul 7, 2009 (gmt 0)

10+ Year Member



Hi,

My current site <snip> is opening from http://www.example.com
But from http://example.com its going to cpanel.

Want http://example.com also to open www.example.com

Current .htaccess is

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

Above is not working also how long will it take for example.com to point to www.example.com after changes.

Please suggest if something completely new has to be done.

Regards
Rajiv

[edited by: engine at 11:41 am (utc) on July 7, 2009]

[edited by: jdMorgan at 4:16 pm (utc) on July 7, 2009]
[edit reason] Please use example.com [/edit]

g1smd

7:07 am on Jul 7, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



That code should ensure the non-www to www redirect (except there is an extra period at the beginning of the condition that ensures that it will never work); however this is likely a DNS problem if that URL doesn't resolve to your site. You need to add an entry to ensure that example.com works.

I would also suggest changing the first line to:

RewriteCond %{HTTP_HOST} [b]![/b]^[b]www\[/b].example\.com$

[edited by: engine at 11:41 am (utc) on July 7, 2009]
[edit reason] examplified [/edit]

rajivadhy

11:15 am on Jul 7, 2009 (gmt 0)

10+ Year Member



Hi would your solution solve the problem or how would I solve the dns issue of example.com

Thanks

jdMorgan

4:19 pm on Jul 7, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Let's keep this thread simple...

Try:


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

Jim

rajivadhy

5:31 am on Jul 8, 2009 (gmt 0)

10+ Year Member



Hi Jim,

I tried this also does it take time to reflect.
My server guys say its software issue as example.com is pinging properly.

Regards
Rajiv

[edited by: jdMorgan at 12:45 pm (utc) on July 8, 2009]
[edit reason] example.com [/edit]

jdMorgan

12:43 pm on Jul 8, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Look at your DNS zone file. Is there an "A record" or CNAME entry for both "example.com." and "www.example.com." (or "*.example.com.")?

Do you have any other rewriterules already working? If not the code above will need to be prefaced with either the second of these lines or both of these lines:


Options +FollowSymLinks -MultiViews
RewriteEngine on

If you are not even sure if mod_rewrite is working on this server, then try an even simpler rule:

Options +FollowSymLinks -MultiViews
RewriteEngine on
#
RewriteRule ^foo\.html$ http://www.google.com/ [R=302,L]

Request the page "/foo.html" from your server, and you should land at google.

Changes made to .htaccess should take effect immediately, as soon as the file is uploaded. On the other hand, changes to DNS will take time to propagate -- about 4 hours for modern/advanced DNS servers, but up to four days for older equipment. Therefore, changes will usually be seen very quickly in developed countries, but may take some time in developing countries.

Please note that we do not allow posting of individual members' domain names -- to protect us, to protect you, and to protect our members.

Jim

[edited by: jdMorgan at 12:45 pm (utc) on July 8, 2009]

rajivadhy

1:36 pm on Jul 8, 2009 (gmt 0)

10+ Year Member



Help Jim,

You have totally confused me, I have the rewrite rules in both htaccess as well as httpd.conf

I guess i will have to do the dns for just example.com
where do i do this in WHM or under the domain registrar personal panel.

Rajiv

[edited by: jdMorgan at 1:51 pm (utc) on July 8, 2009]
[edit reason] example.com. Please see Terms of Service. [/edit]

rajivadhy

1:51 pm on Jul 8, 2009 (gmt 0)

10+ Year Member



Hi Jim

I also have a A entry in dns server.example.com and an ip.

Rajiv

jdMorgan

1:54 pm on Jul 8, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is there an "A record" or CNAME entry for both "example.com." and "www.example.com." (or "*.example.com.")?

You will need at least two entries, one for "server.example.com." and another for "example.com." And note that the trailing period is important.

Jim

[edited by: jdMorgan at 1:54 pm (utc) on July 8, 2009]

rajivadhy

1:59 pm on Jul 8, 2009 (gmt 0)

10+ Year Member



Hi,

I have just one entry for server.example.com thats it no trailing "."

Regards
Rajiv

rajivadhy

2:05 pm on Jul 8, 2009 (gmt 0)

10+ Year Member



in my server panel i have A entry for example.com and www.example.com no trailing "."

Rajiv

jdMorgan

9:46 pm on Jul 8, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It sounds like you need to have a chat with your server support people.

Jim