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 simple .htaccess file that works great on the http version of the site but not when I go to https. Why?

RewriteEngine on
#This is so if the file exists then use the file
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ %{REQUEST_FILENAME} [L]

#These conditions check if a file or folder exists just for reference
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d

#if someone adds ".php" to the slug get rid of it
RewriteRule ^(.*)\.php$ $1  

#don't add the [R] here because we don't want it to redirect
RewriteRule ^(.*)$ index.php?id=$1 [L,QSA]
share|improve this question
add comment

4 Answers

up vote 6 down vote accepted

There's not 100% enough info here to go on, but in the usual default SSL setup (Red Hat/CentOS/Fedora e.g.) the VirtualHost for SSL is set up in it's own container. The use of mod_rewrite requires at a minimum "AllowOverride FileInfo" to be set on the document root for it to act.

Check your config for SSL (/etc/httpd/conf.d/ssl.conf by default), ensure that it looks something like:

DocumentRoot /var/www/html
<Directory /var/www/html>
  AllowOverride FileInfo
</Directory>

The default for AllowOverride is 'None', so any other setting (such as 'All') which adds FileInfo capabilities is OK.

http://httpd.apache.org/docs/2.2/mod/core.html#allowoverride

share|improve this answer
add comment

Could it be possible that mod_rewrite is not enabled for the HTTPS server, or that the .htaccess is not being used?

Check the AllowOveride permissions in use for the regular site and compare against the SSL version, probably a discrepancy. Probably introduced to improve security, if not an accident.

mod_rewrite is next to essential though, so any decent hosting provider should help sort this out.

share|improve this answer
add comment

"working on apache2 + ubuntu precise"

A similar problem occured to me while I was using Slim framework and trying to remove the index.php required in the url. The reWrite worked perfectly for http but for https: it was showing url not found, which meant that the reWrite was not working.

After some hit-n-trial , I came up with this solution:

 cd /etc/apache2/sites-enabled
 sudo vim default-ssl

Change AllowOverride None to All. Similarly sudo vim ssl

share|improve this answer
add comment

I had similar problem, this is what worked for me.

In your httpd.conf, make sure you have both:

ServerName domain.com

ServerAlias www.domain.com

share|improve this answer
add comment

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.