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.

2 Answers 2


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 *:80>
   ServerName www.example.com

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


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"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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