Сценарий
У меня следующая структура каталогов в cPanel
.
public_html/
-folder1/
-folder2/
-example/
-administrator/
-examplefolder2/
-index.html
-.htaccess [inner_htaccess]
-.htaccess [main_htaccess]
Мой домен: example.com
.
.htaccess [inner_htaccess]
# This file has all the contents that are specific to the source code of example. It is based on Joomla and has been working perfectly ever since until I changed server and new structure came into the picture. Now, my shared hosting has primary domain set to example.com.
IndexIgnore *
Options +FollowSymlinks
Options -Indexes
RewriteEngine On
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
RewriteRule .* index.php [F]
RewriteCond %{HTTP_HOST} !^www.example.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
RewriteBase /
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_URI} !^/index\.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]
.htaccess [main_htaccess]
# This htaccess is at the root of public_html where example.com is pointed to by default. Using [this guide][1], I pasted following code.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/example/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /example/$1
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ example/index.html [L]
Конечная цель
example.com
должны серверные файлы с /example
/example
никогда не должно появляться в URL.
index.html
не должно появляться в URL. (Раньше это никогда не приходило)
example.com
должен открываться www
с https
всегда.
- Я не хочу получать доступ к
folder1
& folder2
. Весь запрос к public_html
должен просто передаваться в папку example/
, а затем проверяться правило inner_htaccess
.
Текущее состояние и проблемы
Non www
URL добавляет index.html
к URL. Как:
https://www.example.com/ -> https://www.example.com/ # Okay
http://www.example.com/example/ -> https://www.example.com/ # Okay
http://example.com/ -> https://www.example.com/index.html # Not Okay - Added index.html
https://example.com/ -> https://www.example.com/index.html # Not Okay - Added index.html
Любой URL, начинающийся с www
, не удаляет подпапку example
из URL. Как:
https://www.example.com/example/ -> https://www.example.com/example/ # Not Okay - No removal of subdir in url
http://www.example.com/example/ -> https://www.example.com/example/ # Not Okay - No removal of subdir in url
http://example.com/example/ -> https://www.example.com/ # Okay - Sub Dir removed
https://example.com/example/ -> https://www.example.com/ # Okay - Sub Dir removed
folder1
& folder2
доступны.