如何在没有www的http中将域名重定向到https?

时间:2017-04-22 03:07:26

标签: apache .htaccess vhosts

我想将http://example.com重定向到https://example.com,将http://www.example.com重定向到https://www.example.com。我的应用程序是在Laravel框架版本4.2

中开发的

按照以下链接中的说明,我按照给定的链接编辑了我的.htaccess文件。但它没有用 link of suggestion

.htaccess文件中的完整代码如下所示

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

    RewriteEngine On



# Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond 

%{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301] 

# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

我的http-vhost文件也在下面给出

<VirtualHost *:443>
    DocumentRoot "C:\xampp\htdocs\mysite\example"
    ServerName example.com
    ServerAlias www.example.com
    SSLEngine on
    SSLCertificateFile "conf/ssl/example.crt"
    SSLCertificateKeyFile "conf/ssl/example.key"
    ErrorDocument 404 "ERROR 404 : PAGE NOT FOUND"  
    ##ErrorLog "logs/dummy-host2.example.com-error.log"
    ##CustomLog "logs/dummy-host2.example.com-access.log" common  
  <Directory "C:\xampp\htdocs\mysite\example">
    Order allow,deny
    Allow from all
  </Directory>
</VirtualHost>

有人可以帮我解决这个问题吗?

0 个答案:

没有答案