我想redirect非www和非httpsurl到https://www
为我的域名,我实际上有以下htaccess,工作好redirectnon-https到https,但仍然允许访问domain.com
没有www,
RewriteEngine On RewriteCond %{HTTPS} !=on RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI}%{QUERY_STRING} [L,R] # Redirect Trailing Slashes... RewriteRule ^(.*)/$ /$1 [L,R=301] # Handle Front Controller... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L]
我发现我应该使用以下强制www,但我不能得到它应该放在哪里最好的,谢谢
RewriteCond %{HTTP_HOST} !^www. [NC] RewriteCond %{HTTP_HOST} ^(.+)$ [NC] RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]
您可以使用:
RewriteEngine On RewriteCond %{HTTPS} off [OR] RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule ^ https://www.domain.com%{REQUEST_URI} [R=301,L,NE] # Remove Trailing Slashes... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{THE_REQUEST} \s(.+?)/+[?\s] RewriteRule ^(.+?)/$ /$1 [R=301,L,NE] # Handle Front Controller... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L]