2015-11-14 22 views
2

我應該首先說我不是.htaccess的專家,並且我所做的一切都來自我遵循的教程。鞏固.htaccess並修復問題

我已經編輯股票標準.htaccess文件附帶Laravel包括線是

  • 從URL中移除公共
  • 力HTTPS
  • 重定向到www.mysite.com mysite的請求。 com

我目前遇到的問題是,當我訪問路線mysite.com/sitemapwww.mysite.com/sitemap時,它會生成一個新網站地圖,然後重定向到mysite.com/index.php有效地擺脫Laravel要修復的漂亮的URL。

這是我.htaccess文件在我的公開目錄:

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

    RewriteEngine On 

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

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

    # Redirect www.mysite.com to mysite.com 
    RewriteBase/
    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] 
    RewriteRule ^(.*)$ https://%1/$1 [R=301,L] 

    # Force SSL 
    RewriteCond %{HTTPS} !=on 
    RewriteRule^https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 
</IfModule> 

這是.htaccess文件在我的根目錄

# Remove public 
RewriteEngine On 
RewriteRule ^(.*)$ public/$1 [L] 

這是我routes.php處理sitemap路線

Route::get('sitemap', function(){ 

    // create new sitemap object 
    $sitemap = App::make("sitemap"); 

    // add items to the sitemap (url, date, priority, freq) 
    $sitemap->add(URL::to('/'), '2015-11-14T20:10:00+02:00', '1.0', 'monthly'); 
    $sitemap->add(URL::to('getcv'), '2015-11-14T12:30:00+02:00', '0.9', 'monthly'); 

    // generate your sitemap (format, filename) 
    $sitemap->store('xml', 'sitemap'); 
    // this will generate file sitemap.xml to your public folder 

    return redirect('/'); 

}); 

我的問題是,如何才能讓這個mysite.com/sitemapwww.mysite.com仍然遵循所有的規則在我.htaccess同時重定向到mysite.comsitemap路由,而不是去mysite.com/index.php後?

回答

1

您需要重新排序/public/.htaccess您的規則:

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

    RewriteEngine On 

    # Redirect www.mysite.com to mysite.com 
    RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] 
    RewriteRule^https://%1%{REQUEST_URI} [R=301,L] 

    # Force SSL 
    RewriteCond %{HTTPS} !=on 
    RewriteRule^https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

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

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

確保您在測試此更改清除瀏覽器緩存。

+1

完美,謝謝!我不認爲這個設置有什麼問題,但是沒有足夠的經驗來使用'.htaccess'來實現我需要對它進行重新排序。 – James