2

I have an Amazon EC2 (amzn-ami-pv-2013.09.0.x86_64-ebs (ami-149f7863)) on which I installed Apache, PHP and MySQL.

All works fine until I try to activate .htaccess.

I change AllOverride All in http.conf and restart the Apache service.

When I add the .htaccess file I receive a 500 Internal Server Error even if the htaccess is void.

mod_rewrite.so module is loaded

If I delete the htaccess all works fine.

What I'm doing wrong?

--EDITED--

This is the .htaccess content

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

But even if I left the htaccess file whitout content it returns a 500 error.

The virtualhost definition is the following:

<VirtualHost *:80> ServerAdmin [email protected] DocumentRoot /var/www/html/mywebsite.com ServerName mywebsite.com </VirtualHost> 

--EDITED-2-

I'm sorry but I sorted out this issue only creating the .htaccess file from command line. Now it works. Thank you really for helping me.

--END-EDITING--

Thanks

2 Answers 2

1

What does your Apache error log say? Your site loads without the .htaccess in place, correct?

In my experience, when a 500 error is connected to .htaccess it could be something as simple as the .htaccess file itself getting munged on the file system. I would recommend deleting the actual file and creating a new .htaccess. If that still shows a 500 error, then go through the .htaccess line by line commenting out each line and reload the page. Chances are there is something odd in at least one line and this will show it.

EDIT: I Looked closer at your .htaccess content since you added it & think I spotted the issue. Change it to read like so:

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

It seems like your formatting of the RewriteCond would choke. Also, I adjusted it to the way I would do it which reads in human form:

If this request is not to www.mywebsite.com then redirect it to www.mywebsite.com.

This way you are clearly grabbing anything and everything that is not www.mywebsite.com and sending them to the proper domain.

Also, in your Apache config I would recommend a ServerAlias to account for www.mywebsite.com. It seems like you are using NameVirtualHost so having the main server name be www.mywebsite.com with an alias being mywebsite.com makes the most sense.

<VirtualHost *:80> ServerAdmin [email protected] ServerName www.mywebsite.com ServerAlias mywebsite.com DocumentRoot /var/www/html/mywebsite.com </VirtualHost> 
1
  • 1
    I sorted out this issue only creating the .htaccess file from command line. Thank you for helping me. Commented Nov 16, 2013 at 21:33
0

It's hard to answer your question as such; as you suggest, the .htaccess file itself shouldn't cause your server to return errors. That means its probably what you have written into that file, or perhaps the combination with the apache settings.

I suggest you share the VirtualHost definition and the content of .htaccess tat causes the 500 error.

I also suggest you examine the apache logs, adjusting the config if necessary to obtain verbose enough logs to understand your issue.

At first glance, I'd guess a malformed ReWrite rule, as that's quite easy to do.

2
  • Added some details Commented Nov 16, 2013 at 20:08
  • I sorted out this issue only creating the .htaccess file from command line. Thank you for helping me. Commented Nov 16, 2013 at 21:33

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.