Bead
Bead

Reputation: 363

Apache mod_rewrite, force https, forward from root folder

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:

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

Answers (1)

nikoshr
nikoshr

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

Related Questions