Перенаправить основной домен в подпапку, а также принудительно использовать https ssl - PullRequest
0 голосов
/ 13 апреля 2019

Я перенаправляю свой основной домен в подпапку и хочу, чтобы мой домен использовал HTTPS

С помощью следующего кода я смог бы перенаправить свой основной домен в подпапку.

# .htaccess main domain to subfolder redirect
# Copy and paste the following code into the .htaccess file
# in the public_html folder of your hosting account
# make the changes to the file according to the instructions.

# Do not change this line.
RewriteEngine on

# Change yourdomain.com to be your main domain.
RewriteCond %{HTTP_HOST} ^(www.)?yourdomain.com$

# Change 'subfolder' to be the folder you will use for your main domain.
RewriteCond %{REQUEST_URI} !^/yourdomain.com/

# Don't change this line.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Change 'subfolder' to be the folder you will use for your main domain.
RewriteRule ^(.*)$ /yourdomain.com/$1

# Change yourdomain.com to be your main domain again.
# Change 'subfolder' to be the folder you will use for your main domain
# followed by / then the main file for your site, index.php, index.html, etc.

RewriteCond %{HTTP_HOST} ^(www.)?yourdomain.com$
RewriteRule ^(/)?$ yourdomain.com/index.php [L]

Но в подпапке yourdomain.com есть еще один файл .htaccess, который имеет следующий код.Этот код используется для перенаправления всех запросов URI через файл index.php (шаблон MVC)

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]

Теперь, чтобы заставить домен использовать HTTPS, я напишу следующий код

RewriteEngine on

# PHP -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php70” package as the default “PHP” programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php70 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-SSL} !on
RewriteCond %{HTTP_HOST} ^yourdomain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.yourdomain\.com$
RewriteRule ^/?$ "https\:\/\/yourdomain\.com\/" [R=301,L]

Я не уверен, куда мне поместить приведенный выше код, чтобы заставить домен использовать HTTPS.Я пытался поместить его в подпапки .htaccess, но выдает следующую ошибку:

Запрошенный URL /yourdomain.com/url=index.php не найден на этом сервере.

Я хотел бы добиться следующих вещей:

  1. Перенаправить основной домен в подпапку с именем yourdomain.com
  2. Перенаправить весь веб-трафик в файл index.php, которыйбудет в подпапке (MVC Pattern).
  3. Принудительно использовать домен вместо HTTPS HTTPS.

Спасибо!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...