我目前正试图弄清楚下面的困境。从另一个目录加载资产
例子:
访问网址:http://localhost/admin/content/1/builder
iframe网址(页):http://localhost/templates/silver-1/index.html
现在里面的index.html的资产将被要求像:
<link rel="stylesheet" href="css/site.css">
我当然无法使用{{asset('css/site.css')}},因为这是一个.html文件,它将用于迟到的页面构建器r获得“编译”到blade.php文件。
而不是更换所有资产的URL,当我“编译”我想重定向他们,如果他们得到要求以这种方式页面:
http://localhost/1/css/site.css>http://localhost/templates/silver-1/css/site.css http://localhost/1/some_sub_dir/css/site.css>http://localhost/templates/silver-1/css/site.css
现在我做了讨厌变通通过使用以下路线:
Route::get('/{id}/{dir?}/{path?}', function($id, $dir = null, $path = null) {
$page = Session::get('Site.current.page');
$location = Session::get('Site.current.template_location');
if(!$page || $page != $id) {
if(is_numeric($id)) {
$page = Frontend\Models\Page::find($id);
$location = $page->template->template_location;
Session::put('Site.current.page', $page->id);
Session::put('Site.current.template_location', $location);
}
}
$p = plugin_path('Frontend', sprintf('templates/%s/%s/%s', $location, $dir, $path));
if(!file_exists($p)) {
return null;
}
return Redirect::to(plugin_asset('Frontend', sprintf('templates/%s/%s/%s', $location, $dir, $path)));
})
->where('id', '[0-9]')
->where('dir', 'js|css|img|font|vendors|stylesheets|images|assets|js-files')
->where('path', '(.*)');
现在请原谅我,因为我自己发现代码可怕,破碎和垃圾,因此为什么我正在寻找一个更好的方式来解决它或者与.htaccess或其他东西...
我试过结合重定向laravel的.htaccess这是遵循内部声明:
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]
不管我做什么用的.htaccess我要么清盘打破它(500/laravel路由borked)
任何帮助是很大的赞赏,如果需要更多的代码或解释,请在下面评论。
预先感谢您。
我真的很可怕的htaccess配置,我会在哪里把它放在我上面显示的htaccess? –
如果您的重写过程是可以尝试的,您也可以根据自己的需要操作它 –
无法使用当前设置进行操作。它不会重定向网址。 –