【发布时间】:2016-02-15 20:42:20
【问题描述】:
首先我应该说我不是 .htaccess 的专家,我所做的一切都来自我遵循的教程。
我已经编辑了 Laravel 附带的标准 .htaccess 文件以包含以下行
- 从 URL 中删除公共
- 强制 https
- 将对 www.mysite.com 的请求重定向到 mysite.com
我目前遇到的问题是,当我访问路线 mysite.com/sitemap 或 www.mysite.com/sitemap 时,它会生成一个新的站点地图,然后重定向到 mysite.com/index.php,从而有效地摆脱 Laravel 旨在修复的漂亮网址.
这是我的公共目录中的.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/sitemap 或www.mysite.com 仍然遵循我的.htaccess 中的所有规则,同时在遵循sitemap 路线而不是去@ 之后重定向到mysite.com 987654338@?
【问题讨论】:
标签: apache .htaccess laravel mod-rewrite laravel-5