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 a hosted website which includes a secure regiatration and purchase section which provides access to paid content. The SSL certificate validation will fail if the url is not in the form www.domainname.com. I was looking at using mod_rewrite rules to redirect if www was not found in the url. This works but then the redirect to the secure pages fails with a 500 error. Checking the ssl_error logs I see:

[Wed Jul 29 21:20:32 2009] [alert] [client xx.xx.xx.xx] /vservers/domainname/htdocs/.htaccess: RewriteEngine not allowed here, referer: http://www.domainname.com/index.php?option=com_content&view=category&id=2&Item=9

.htaccess we tried:

#  mod_rewrite in use
RewriteEngine On

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

I'm not sure if this is something I can fix or must I wait for the hosting provider to get around to the problem.

share|improve this question

2 Answers 2

up vote 2 down vote accepted

As has been pointed out, you can only use RewriteEngine in the central configuration, not in .htaccess. As the error was not that it did not recognise RewriteEngine, you can be certain that mod_rewrite is installed. What you can't be sure of is whether RewriteEngine has been enabled for your vhost. The best thing to do is to try it.

If the site you're hosting is dynamic, you could add some code to check $SERVER_NAME and redirect appropriately, but this may be too much effort if you don't have a single place where you could add the code.

Otherwise, I'd say you're stuck waiting for your provider.

If you could have modified your central config, you can do this easily without installing any additional modules and without using mod_rewrite. I find people spend ages trying to use mod_rewrite when there are easier ways of doing things.

<VirtualHost *:80>
   ServerName example.com
   Redirect / http://www.example.com
</VirtualHost>

<VirtualHost *:80>
   ServerName www.example.com
   .
   .
   .
</VirtualHost>

You can add additional 'ServerAlias' lines to the top virtual host if you need more than one host to redirect.

share|improve this answer

It seems you can't use rewriteengine there. If you can't change your apaChe config, the only thing you can try is removing the "RewriteEngine on" and expect mod_rewrite to be enabled server-wide

If you can change apache conf, either move RewriteEngine there or add "AllowOverride all"

share|improve this answer

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.