Welcome to WebmasterWorld Guest from 54.196.2.131

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Redirecting All Subdomains to WWW

getting 500 errors

     
9:05 pm on Mar 17, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 6, 2003
posts:2523
votes: 0


Getting [example.com...] to redirect to [example.com...] is easy, and have successfully implemented it on all of my sites, thanks to WW.

I have a host that I have wildcard subdomains active, but I need all the subdomains to 301 to the WWW version.

I tried the code below, but all I managed to do was get my server to produce 500 internal server errors.

Options +FollowSymlinks 
RewriteEngine on
RewriteCond %{HTTP_HOST}!^www\.example\.com.tld
RewriteRule (.*) http://www.example.com.tld [R=Permanent]

I searched the forum, I swear. help

11:11 pm on Mar 17, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:Mar 8, 2005
posts:118
votes: 0



RewriteCond %{HTTP_HOST}!^www\.example\.com.tld

Looks like you are missing a \ before the .tld?

I don't know a lot about mod rewrite but as a programmer that part does stand out as out of place with the format of the rest of the statment.

12:11 am on Mar 18, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 6, 2003
posts:2523
votes: 0


That was a good guess, but that's not it. Still getting a 500 internal error.

I am not sure if i need to put the extra slash in, for the non-www to www redirect its not necessary.

Anyone else?

12:45 am on Mar 18, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


Missing space before "!".
Add check for blank HOST to prevent problems with HTTP/1.0 clients.
Retain requested page path and apply to new URL.
Add [L] (Last Rule) flag to redirect immediately.

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.example\.com.tld
RewriteRule (.*) http://www.example.com.tld/$1 [R=Permanent,L]

The above is for use in .htaccess. If you put the code into httpd.conf, change the rule as follows:

RewriteRule [b]^/[/b](.*) http://www.example.com.tld/$1 [R=Permanent,L]

If you still have problems, please post the relevant contents of your server error log.

Jim

1:46 am on Mar 18, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 6, 2003
posts:2523
votes: 0


Thank you Jim - that fixed it - works great. Now I have the power to rule the universe!

muahahahaha!

:)

i owe you a beer

3:43 am on Mar 20, 2005 (gmt 0)

Senior Member

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

joined:June 4, 2002
posts:1830
votes: 3


I have 2 questions:

I have set up the .htaccess file to redirect non-www to www.

However I have also see links coming into my site such as "http/" or http:/"

Do I need to redirect these also? If so, how do I change the code I've posted below?

2nd question.

I have several subdirectories with their own index page. Do I need to put an htaccess in those files also or will the root htaccess cover everything. If I need to can someone show me how to alter the following:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule ^(.*)$ [example.com...] [R=permanent,L]