0

我在共享虚拟主机上使用 Laravel 5.4。网站运行良好,没有任何功能问题。我总是强制使用 HTTPS + WWW。

但是从无效/不存在的页面重定向后,URL 路径存在问题。

而不是https://www.example.com/在 URL 中显示https://www.example.com/public/

/public/如果我转到任何现有页面,则没有重定向。无论有没有/public/. 对于访问者来说,有时它/public/在 URL 的末尾,有时它没有,这可能会让人感到困惑。例如,通常我有 URL https://www.example.com/about,但它也可以https://www.example.com/public/about在这种情况下工作,我也不确定可能存在的漏洞。

我有 2 个 .htaccess 文件,一个在项目根文件夹中public_html,另一个在 Laravel 公共文件夹public_html/public中。

1) public_html/.htaccess

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_URI} !^public
    RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
    RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
    RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

2) public_html/public/.htaccess

<IfModule mod_rewrite.c>

<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

RewriteEngine On

# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule \.(txt|xml)$ - [L]

# Force SSL + WWW
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]

</IfModule>
4

0 回答 0