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.

Answers


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:

RewriteBase /

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/


Need Your Help

How can I test that a value is “greater than or equal to” in Jasmine?

javascript tdd jasmine

I want to confirm that a value is a decimal (or 0), so the number should be greater than or equal to zero and less than 1.

Handle connections using sockets at four different ports

c linux sockets select port

I try to make a client/server system in C on a Linux platform. I want to listen on four different ports. Therefore I create four file descriptors, one for each port. Additionally the process binds ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.