Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have migrated to a new server and when ever I try to use my site with the www prefix I get a 500 internal server error. This use to work on my previous host just fine. Here is a snippet of the htaccess file which refers to the www - no where else does it refer to the www.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^blog/ - [L]
RewriteCond %{HTTP_HOST} ^www\.mydomain\.com$ [NC]
RewriteRule ^(.*)$ http://mydomain.com/$1
RewriteRule ^search/(.*)/(.*)/(.*)/(.*) /search.php?searchfor=$1&sortby=$2&page=$3&searchterm=$4
RewriteRule ^confirmemail/(.*) /confirmemail.php?code=$1
RewriteRule ^resetpassword/(.*) /resetpassword.php?code=$1
RewriteRule ^resendconfirmation/(.*) /resendconfirmation.php?userid=$1
RewriteRule ^categories/ /categories.php
RewriteRule ^([-_~*a-zA-Z0-9]+)(\/)?$ /memberprofile.php?username=$1
RewriteRule ^browse/audios/(.*)/(.*)/(.*)/(.*) /audios.php?sortby=$1&filter=$2&page=$3&title=$4
RewriteRule ^browse/categories/audios/(.*)/(.*)/(.*)/(.*) /categoryaudios.php?sortby=$1&filter=$2&page=$3&title=$4
RewriteRule ^audios/(.*)/(.*) /playaudio.php?audioid=$1&title=$2
RewriteRule ^download/audio/(.*)/(.*) /downloadaudio.php?AUDIOID=$1&title=$2
RewriteRule ^members/audios/(.*)/(.*) /memberaudios.php?pid=$1&username=$2
RewriteRule ^syndicate/audios/(.*)/(.*) /syndicateaudios.php?filter=$1&title=$2
</IfModule>

What else can I check?

I have setup this domain up with Plesk Control Panel - maybe this is the issue?

Thanks all for any help

Update

The error logs show this when i go to my site using the www prefix.

[Wed Sep 08 13:57:24 2010] [error] [client xx.xxx.xx.xxx] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

Update 2

My site has a server alias in the httpd.conf file of the form serverAlias www.mydomain.com - can this cause redirect loop?

Update 3

I was not able to get apache to create or write to the rewrite log and I don't want to do too many service restarts since there are people using the site.

I have added a bounty to this question as I really need help!

share|improve this question
    
Do you have an error message, not just the error code? –  Christian Sep 8 '10 at 11:37
    
Check your Apache httpd's ErrorLog for the domain. –  joschi Sep 8 '10 at 11:51
    
@Christian - The message is "The server encountered an internal error or misconfiguration and was unable to complete your request." –  Abs Sep 8 '10 at 11:54
    
@joschi - I have updated my question with the error that is shown. –  Abs Sep 8 '10 at 11:59
    
Use RewriteLog and RewriteLogLevel to see which redirections occur on your rewrite rules. –  joschi Sep 8 '10 at 12:25

3 Answers 3

up vote 2 down vote accepted
+50

This is interesting because the logs state that a redirect is happening, but you do not have any rules which use the [R] flag. However, when a rule includes http://... the [R] flag is redundant, so the

RewriteRule ^(.*)$ http://mydomain.com/$1

rule is the likely candidate for causing the problem.

If I were you, I would try putting [R=301,L] at the end of that line to make sure the other rules aren't somehow using the previous host name, somehow resulting in a loop.

Another possibility is that PHP is involved in the redirect loop. Can you access the www site with Firefox and the livehttpheaders plugin, and share the headers here? That may shed some light on what is causing the redirect loop.

I do not think that the fact that Plesk is involved has anything to do with it, and no, I don't think the ServerAlias has anything to do with it. That only allows the same configuration to be served for both virtual hosts: www.example.com and example.com.

Hope that helps!

share|improve this answer
    
You sir, are what we call a genius! :) That worked perfectly! Thank you so much, this saved me!...Bounty will be awarded in 22 hours... –  Abs Sep 13 '10 at 13:35
    
+1 I didn't know about the http://=[R] bit, thats damn handy to know! –  Grizly Sep 14 '10 at 0:39
    
Glad I helped! I <3 mod_rewrite. Ralf S. Engelschall rocks! –  Docunext Sep 14 '10 at 12:46

How about:

<IfModule mod_rewrite.c>
RewriteEngine On
ReWriteCond %{HTTP_HOST} !^mydomain
ReWriteRule ^(.*)$ http://mydomain.com/$1
...
</IfModule>
share|improve this answer
    
Will this cause problems with subdomains? –  Abs Sep 8 '10 at 12:32
    
The RewriteCond only works on the first RewriteRule immediately after it. We are saying here, if the host does not start with mydomain, redirect it. So maybe.. your question didn't mention subdomains. –  Grizly Sep 8 '10 at 12:33

There's also a rewrite log, activate it and see what happens.

For most of cases it is a reentrant rule.

share|improve this answer
    
This is strange - I have enabled this for my domain, however nothing appears in that log. Maybe I need to do something different in Plesk. I have restarted apache btw. –  Abs Sep 8 '10 at 12:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.