I have searched and while I found lots of threads close, none were exactly what I am looking for…
On my site, say example.com, I’ve created the subdomain secure.example.com
This subdomain will have SSL.
What I want to do is redirect requests to https://secure.example.com/path/ to http://www.example.com/path/ while keeping the url showing as https://secure.example.com/path/
note that the purpose of subdomain.example.com is for SSL so the redirect above will need to work with SSL
I would like to use a few other redirects in the htaccess:
1) redirect non-www to www ignoring subdomains (so secure.example.com doesn’t become http://www.secure.example.com)
2) redirect /index.php to /
3) and last but not least, force SSL on secure.example.com
In addition the shopping cart software has additional htaccess statements for functionality and SEO as seen below.
My current root htaccess:
# Prevent Directoy listing
Options -Indexes
# Prevent Direct Access to files
<FilesMatch "\.(tpl|ini|log)">
Order deny,allow
Deny from all
</FilesMatch>
# Turn Rewrite Engine On
RewriteEngine On
## index.php to root
Options +FollowSymlinks
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://www.example.com/ [R=301,L]
## non-www to www ignore subdomains
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
Well, specifically for the url
https://secure.example.com/path/to display content found athttp://www.example.com/path/, there’s 2 things that you can do. The best thing is if the 2 domains are served from the same document root:The subdirectory might be a problem, since it may not be able to rewrite out of its own document root. For example:
If you had an .htaccess file in
/path/to/htdocs/secureto rewrite requests forhttps://secure.example.com/. The problem here is you need to rewrite to the parent directory, and apache won’t let you do that. If it was the other way around, you could rewrite requests forhttp://www.example.com/to/secure. Also, if the two domains had the same document root, you could also rewrite. But not if secure is a subdirectory to www’s document root.That means you can at least use the
Prewrite flag to send the request off to mod_proxy, so you can do something like this:in the htaccess file in your secure.example.com’s document root. That will only proxy specifically the URI
/path/, and not anything like/path/foo/bar.html. If you want everything starting with/path/, then you can match against it:If there are redirection issues, you may want to resort to using
ProxyPassinstead:It does the same thing except it rewrites location headers so redirects also get proxied.