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

non-www to www 301 redirect
301 redirect returns internal server error

 12:12 pm on Jun 29, 2012 (gmt 0)

I have 2 websites that share the same server. I use the below code for non-www to www 301 redirect. One of the websites is working perfectly while the other is returning an internal server error when I try to visit the website. I have the code placed in each sites respective folder that contains that sites index file. I have chmod permissions set to 0664 for both sites.

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^example.com [nc]
rewriterule ^(.*)$ http://www.example.com/$1 [r=301,nc]

Would anyone have any idea as to what I am doing incorrectly?

Kind regards and thanks in advance for any help,



 12:16 pm on Jun 29, 2012 (gmt 0)

Try this in each site.

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

Try it without the Options line too.


 1:12 pm on Jun 29, 2012 (gmt 0)

Thank you for your quick reply. I tried the new script but I am still having the same problem. One site works as expected. The other site returns the following error:

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, [no address given] and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Thank you,


 1:18 pm on Jun 29, 2012 (gmt 0)

So, what does it say in the server error log?

That's server error log, not access log.


 2:19 pm on Jun 29, 2012 (gmt 0)

Listed below are parts, of some of the lines, of the error log.

.htaccess: Expected </html>RewriteEngine> but saw </html>

.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable, referer: http://www.example.com/

Thanks for trying to help,


 2:23 pm on Jun 29, 2012 (gmt 0)

Why have you got HTML tags in your htaccess file?


 3:12 pm on Jun 29, 2012 (gmt 0)

hmmmmmmm--I don't. Maybe somehow the file manager is adding them in. I will check that.



 3:22 pm on Jun 29, 2012 (gmt 0)

Okay--the file manager/file editor was in html mode. I clicked and changed it to text mode and entered the script. I am now getting a different message when I try to visit the web page.

The website declined to show this webpage
HTTP 403
Most likely causes:
•This website requires you to log in.
What you can try:
Go back to the previous page.
More information

Thanks for your help,


 3:24 pm on Jun 29, 2012 (gmt 0)

from log file:

htdocs/example/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable


 3:31 pm on Jun 29, 2012 (gmt 0)

I went back in and changed the permissions from 640 to 644 and now everything is working. I cannot tell you enough how grateful I am for your help. Could I please ask what is the difference between chmod 640 and 644 and is it okay to use 644?

Kind regards,

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