Apache, redirect to HTTPS everything except some files...
I have a static redirect from HTTP to HTTPS using virtual hosts and apache…
I have used this config.
<virtualhost *:80="">DocumentRoot /home/mydomain/public_html
ServerName www.mydomain.org
ServerAlias www.mydomain.org
ErrorLog /var/log/httpd/mydomain/error_log
CustomLog /var/log/httpd/mydomain/access_log common
Redirect permanent / https://www.mydomain.org</virtualhost>
<virtualhost _default_:8443="">DocumentRoot /home/mydomain/public_html
ServerName www.mydomain.org
ServerAlias www.mydomain.org
ErrorLog /var/log/httpd/mydomain/error_log
CustomLog /var/log/httpd/mydomain/access_log common</virtualhost>
I would like to redirect all except those files
/home/mydomain/public_html/file1.php
and
/home/mydomain/public_html/myfolder/file2.php
How can I do it?
I know that I could use RedirectMatch instead of Redirect but what is the correct syntax?
Thanks!!!
1 Reply
tommydavidson
Linode Staff
You should be able to make this work using a RewriteRule, such as the one outlined in the example here. For convenience, I've copied the example rule into the code block below:
RewriteEngine On
# Go to https if not on /your-page-url/
RewriteCond %{SERVER_PORT} =80
RewriteCond %{THE_REQUEST} !/your-page-url/ [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Go to http if on /your-page-url/
RewriteCond %{SERVER_PORT} !=80
RewriteCond %{THE_REQUEST} /your-page-url/ [NC]
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]