首先,我要警告您,我看过很多其他主题,但找不到解决方案,所以我决定打开这个新主题。
我正在尝试做一个简单的事情,使用htaccess中的规则在每个站点上强制使用SSL,但是我已经测试了几种规则格式,并且都返回错误500。
我原来的htaccess如下:
# You need to uncomment the below line if you see errors in browser console like this: "Refused to execute inline script because it violates the following Content Security Policy directive: “script-src ‘self’ ..."
#Header set Content-Security-Policy "script-src 'self' 'unsafe-inline' 'unsafe-eval' https://*.jquery.com *.googlesyndication.com https://adservice.google.ru https://adservice.google.com *.google-analytics.com https://*.facebook.net https://*.twitter.com https://cdn.syndication.twimg.com https://*.cloudflare.com;"
<IfModule mod_rewrite.c>
RewriteEngine On
# Some servers require you to specify the `RewriteBase` directive
# In such cases, it should be the path (relative to the document root) containing this .htaccess file
#
# RewriteBase /
# deny direct access to files in application folders
RewriteRule ^(app|config|db|logs|tmp|vendor)\/.*$ - [R=403,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L,QSA]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
</IfModule>
<IfModule !mod_rewrite.c>
Order allow,deny
Deny from All
</IfModule>
我尝试了各种规则,但是例如,如果我使用以下规则,它们都会返回错误500:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://mywebsite.com/$1 [R,L]
我得到以下日志:
/public_html/.htaccess: Expected </IfModule> but saw </IfModule>RewriteEngin>
我尝试了各种规则,但是例如,如果我使用以下规则,它们都会返回错误500:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
我得到以下日志:
/public_html/.htaccess: Expected </IfModule> but saw </IfModule>RewriteEngin>
无论如何,我测试了其他规则,它们都返回500错误,以此为基础,有经验的人可以帮我吗?
预先感谢您的帮助!