2017-05-05 70 views
0

我目前正試圖弄清楚下面的困境。從另一個目錄加載資產

例子:

訪問網址: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)

任何幫助是很大的讚賞,如果需要更多的代碼或解釋,請在下面評論。

預先感謝您。

回答

1

添加到您的htaccess

RewriteRule ^css yoursubfolder/css [QSA,NC] 

基本上你可以將其重定向到你喜歡

你也應該調用像/css/site.css你的CSS文件夾,以便它會嘗試得到任何路徑根css文件夾

+0

我真的很可怕的htaccess配置,我會在哪裏把它放在我上面顯示的htaccess? –

+0

如果您的重寫過程是可以嘗試的,您也可以根據自己的需要操作它 –

+0

無法使用當前設置進行操作。它不會重定向網址。 –

相關問題