I have not having any luck getting my .htaccess with mod_rewrite working. Basically all I am trying to do is remove \'www\' from \"http://www.example.com\" and \"https://ww
As Vinko said,
RewriteLog "/tmp/rewrite.log"
RewriteLogLevel 9
and look at that file.
Otherwise, here's the code we're using to redirect from zirconium.zrs.hr/~zatemas to zatemas.zrs.hr:
RewriteEngine on
# For sites running on a port other than 80
RewriteCond %{HTTP_HOST} !^zatemas\.zrs\.hr [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{SERVER_PORT} !^80$
RewriteRule ^/~zatemas/(.*) http://zatemas.zrs.hr:%{SERVER_PORT}/$1 [L,R]
# And for a site running on port 80
RewriteCond %{HTTP_HOST} !^192\.168\.1\.24 [NC]
RewriteCond %{HTTP_HOST} !^zatemas\.zrs\.hr [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/~zatemas/(.*) http://zatemas.zrs.hr/$1 [L,R]
I've seen around the web that people detect HTTPS primarily by looking if the port is 443. mod_rewrite documentation says there should be a variable HTTPS set to on or off, appropriately - I presume you do RewriteCond %{HTTPS} ^on$
to test if it's on.
Also watch out: .htaccess
directives for URL rewriting do not work nicely if you're accessing files in user's home directory - for example example.com/~username/. That should not bother you according to your scenario, though. My code above is placed in main server config, under the VirtualHost
section(more precisely, in /etc/apache2/sites-enabled/000-default
, but that's debian specific and gets merged in main config).
I had the same problem and this wasted my 5 hours to fix.
So In order to use mod_rewrite you can type the following command in the terminal:
a2enmod rewrite
Then restart your Apache.
In my case, I changed in httpd.conf:
AllowOverride None
to
AllowOverride All
and it works.
What are the file permissions for your .htaccess file?
I'm not sure, but I think it needs to be 644.