.htaccess Laravel www到非www不工作,文件夹重定向

emeijp43  于 2022-11-16  发布在  其他
关注(0)|答案(1)|浏览(157)

我在htaccess文件中有设置代码。将https://www.website.com/重定向到https://website.com/,但两个链接的工作方式相同。

SetEnv PHPRC /home/customer/www/website.com/public_html/php.ini
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^(.*)$ public/$1 [L]
    RewriteCond %{HTTP_HOST} ^www.website.com [NC]
    RewriteRule ^(.*)$ http://website.com/$1 [L,R=301]
</IfModule>
<IfModule mod_rewrite.c>

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

  # Disable Directory listing
Options -Indexes

# block files which needs to be hidden, specify .example extension of the file
<Files ~ "\.(env|json|config.js|md|gitignore|gitattributes|lock)$">
    Order allow,deny
    Deny from all
</Files>
</IfModule>

<IfModule mod_headers.c>
Header set Cache-Control "private"
</IfModule>
AddHandler application/x-httpd-php80 .php .php5 .php4 .php3
wnavrhmk

wnavrhmk1#

试试这个

RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
  1. http到https
  2. www到非www

相关问题