2016-05-17 175 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