Apache2 - .htaccess将所有内容重定向到https:// www

时间:2015-11-05 12:37:36

标签: apache2

我需要一个htaccess规则,将http://oursite.comhttp://www.oursite.com等所有类型的页面重定向到httpS://WWW.oursite.com

你能给我那种规则吗?

<IfModule mod_rewrite.c>
ErrorDocument 404 /page-404.php
RewriteEngine On

        RewriteCond %{REQUEST_FILENAME} -f [OR]
        RewriteCond %{REQUEST_FILENAME} -d
        RewriteRule .+ - [L]

RewriteCond %{THE_REQUEST} ^[A-Z]+\s([^\s]+)\.php\s [NC]
RewriteRule .* %1.html [R=301,L]

# make sure .php file exists for the requested .html file
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)\.html$ $1.php [L,NC]
</IfModule>

提前致谢!

1 个答案:

答案 0 :(得分:0)

简短而简单:

<ifmodule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{HTTPS} off
  RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</ifmodule>