2016-05-17 87 views
2

我有域 - example.com。我使用Laravel 5.www和https htaccess重定向问题

我想总是重定向到https://www.example.com/beta

现在,我的htaccess的是:

<IfModule mod_rewrite.c> 
    <IfModule mod_negotiation.c> 
     Options -MultiViews 
    </IfModule> 
    RewriteEngine On 
    RewriteBase /beta/ 

    RewriteCond %{HTTP_HOST} !^www\. [NC] 
    RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 
    RewriteCond %{HTTPS} !=on 
    RewriteRule^https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301] 

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

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

现在,对于example.com/beta - 它重定向到https://example.com/beta

但是当我们去www.example.com/beta - 它重定向到http://www.example.com/https://www.www.example.com/beta

请指教。

回答

2

有这样说:

<IfModule mod_rewrite.c> 
    <IfModule mod_negotiation.c> 
     Options -MultiViews 
    </IfModule> 
    RewriteEngine On 
    RewriteBase /beta/ 

    RewriteCond %{HTTP_HOST} !^www\. [NC,OR] 
    RewriteCond %{HTTPS} !=on 
    RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC] 
    RewriteRule ^(.*)$ https://www.%1%{REQUEST_URI} [L,R=301,NE] 

    # Redirect Trailing Slashes... 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*)/$ /$1 [L,R=301,NE] 

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

确保测试这种变化之前清除浏览器缓存。

+0

你能告诉我我的代码出了什么问题吗? – dang

+0

你的第二条规则是在请求可能已经有'www' – anubhava

+0

@anubhava的同时加入'https'和'www'亲爱的你能回答我的问题吗,如果你有时间吗? [问题](http://stackoverflow.com/questions/37435512/request-404-page-not-found-ajax) – Azzo

相关问题