.htaccess毫无例外地将所有请求重写到子文件夹

时间:2018-09-12 02:44:32

标签: apache .htaccess mod-rewrite url-rewriting shared-hosting

场景

我在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]

最终目标

  1. example.com应该从/example服务器服务器文件
  2. /example不应出现在网址中。
  3. index.html不应出现在url中。 (以前从来没有来过)
  4. example.com应该始终以www打开https
  5. 我不想访问folder1folder2。对public_html的所有请求都应该简单地传递到example/文件夹中,然后检查inner_htaccess规则。

当前状态和问题

  1. Non www网址将index.html附加到网址。喜欢:

    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
    
  2. 任何以www开头的网址都不会从网址中删除example子文件夹。喜欢:

    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
    
  3. folder1folder2可以访问。

0 个答案:

没有答案
相关问题