Reputation: 363
I asked a question about this yesterday but I am still having trouble with my httpd.conf.
What I would like to happen is this:
User requests http://www.mysite.com/
or mysite.com
, etc. They are then redirected to https://www.mysite.com/shop/
I would also like to make sure that any request under the /shop
subdirectory is rewritten to HTTPS as well, even if the user types in http://www.mysite.com/shop/help/
it would be rewritten as https://www.mysite.com/shop/help/
Here is my configuration right now, which isn't working.
Listen *:443 https
Listen *:80 http
<VirtualHost *:80>
RewriteEngine on
ReWriteCond %{SERVER_PORT} !^443$
RewriteRule ^(shop/.*)$ https://%{HTTP_HOST}/shop/$1 [NC,R=301]
RewriteRule ^/$ https://%{HTTP_HOST}/shop/ [NC,R=301,L]
</VirtualHost>
<VirtualHost *:443>
SSLEngine On
SSLAppName QIBM_HTTP_SERVER_ZENDSVR
SetEnv HTTPS_PORT 443
RewriteEngine on
RewriteRule ^/$ https://%{HTTP_HOST}/shop/ [NC,R=301]
</VirtualHost>
Upvotes: 0
Views: 1331
Reputation: 33344
First, make sure mod_rewrite kicks in when your server receives a request. For example, to redirect all requests from your HTTP host to your HTTPS server
<VirtualHost *:80>
RewriteEngine on
RewriteRule .* https://%{HTTP_HOST}/shop/ [R,L]
</VirtualHost>
Then try
<VirtualHost *:80>
RewriteEngine on
RewriteRule ^/?shop/(.*) https://%{HTTP_HOST}/shop/$1 [NC,R=301,L]
RewriteRule ^/?$ https://%{HTTP_HOST}/shop/ [R=301,L]
# other directives
</VirtualHost>
<VirtualHost *:443>
RewriteEngine on
RewriteRule ^/?$ https://%{HTTP_HOST}/shop/ [R=301,L]
# other directives
</VirtualHost>
Upvotes: 1