htaccess RewriteEngine working for HTTP but not HTTPS
I am trying to redirect URLs such as www.mysite.com/foo/bar to www.mysite.com/foo/index.php?foo=bar.
To do this I am using a couple of lines in the .htaccess file, they are as follows:
RewriteEngine On RewriteRule ^foo/([a-z]+)/?$ foo/index.php?bar=$1 [NC,L]
This works great for connections made over HTTP but I really need this to work over HTTPS as well. When I go to https://www.mysite.com/foo/bar I just get presented with the 404 Not Found error page.
Any help to get this working over HTTPS (or an explanation as to why it cannot be done over HTTPS) would be great. Thanks.
EDIT: After reading a few comments here is a bit of an update.
- I do have an SSL certificate for the site and HTTPS is working fine elsewhere on the site
- The document root is the same for both the HTTPS and the HTTP versions of the site. I checked this out using echo $_SERVER['DOCUMENT_ROOT']; - both return the same thing.
- I did notice that (when I removed my customised 404 page) that the error shown is: The requested URL document_root/public_html/foo/index.php was not found on this server. I do not have any idea why this might be the case when, if I access the file directly, I can use it fine.
Hopefully this extra info might help a bit.
After some more searching for solutions and looking at examples of .htaccess files I found the solution. I needed to add the following line to my .htaccess file:
I am still unsure as to why, without this line, it worked using HTTP but not HTTPS but everything is working well with the addition of this line.
I am no expert in this area but I found a nice explanation of what RewriteBase does here (Line 4): http://randomtype.ca/blog/the-wordpress-htaccess-file-explained/