Перенаправление во вложенную папку, а также перенаправление http на https

Я делаю перенаправление с URL-адреса непосредственно на вложенную папку (пример: redirect www.example.comto www.example.com/subfolder), которая отлично работает следующим образом:

RewriteEngine on 
RewriteCond %{REQUEST_URI} !^/1 
RewriteRule (.*) http://www.example.com/subfolder/

I am doing a redirection from an URL directly to an subfolder (example: redirect www.example.com to www.example.com/subfolder), which is working perfectly as following:

RewriteEngine on 
RewriteCond %{REQUEST_URI} !^/1 
RewriteRule (.*) http://www.example.com/subfolder/$1 [L]

Additionally (if possible using the same .htaccess file) I would like to redirect any http to https, which works fine using the following:

RewriteEngine On
RewriteCond %{SERVER_PORT}   !^443$
RewriteRule  (.*)  https://%{HTTP_HOST}/$1   [L]

How do I combine those two redirections into one .htaccess file? So finally the redirection from http to https and the redirection to the subfolder?

Thanks a lot!

[L]

Дополнительно (если возможно используя то же самое .htaccess) я хотел бы перенаправить любой http на https, который отлично работает, используя следующее:

RewriteEngine On
RewriteCond %{SERVER_PORT}   !^443$
RewriteRule  (.*)  https://%{HTTP_HOST}/

I am doing a redirection from an URL directly to an subfolder (example: redirect www.example.com to www.example.com/subfolder), which is working perfectly as following:

RewriteEngine on 
RewriteCond %{REQUEST_URI} !^/1 
RewriteRule (.*) http://www.example.com/subfolder/$1 [L]

Additionally (if possible using the same .htaccess file) I would like to redirect any http to https, which works fine using the following:

RewriteEngine On
RewriteCond %{SERVER_PORT}   !^443$
RewriteRule  (.*)  https://%{HTTP_HOST}/$1   [L]

How do I combine those two redirections into one .htaccess file? So finally the redirection from http to https and the redirection to the subfolder?

Thanks a lot!

[L]

Как объединить эти два перенаправления в одно .htaccess? Итак, наконец, перенаправление с http на https и перенаправление в подпапку?

Большое спасибо!

1 ответ

  1. Можно использовать следующее правило

    RewriteEngine on
    #http to https 
    RewriteCond %{HTTPS} off
    RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R]
    #Rewrite everything to subfolder
    RewriteRule !subfolder /subfolder%{REQUEST_URI} [L]