duanpan3166 2017-06-20 18:58
浏览 30

public urri自动出现在url laravel中

I am using shared hosting for hosting a laravel application. I have used a .htaccess file to redirect request to the public folder

RewriteEngine on 
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$ 
RewriteCond %{REQUEST_URI} !^/public/ 
RewriteRule ^(.*)$ /public/$1 
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$ 
RewriteRule ^(/)?$ public/index.php[L]

the laravel routing works perfectly but when i try to request a folder inside the public folder directly from the url a public uri automatically appears

eg: when i write "www.domain.com/Uploads" the url automatically becomes "www.domain.com/public/Uploads"

  • 写回答

1条回答 默认 最新

  • dongluo6343 2017-06-20 19:03
    关注

    You don't have to use htacess to access your files. A better way to do it is to build a route that fetches the file you need and present it to you.

    Lets say the url is

    project.dev/images/image.jpg
    

    Building a route like this will fetch the file you need

    Route::get('/images/{name}', function($name) {
        $file = Storage::get('images/'.$name);
    
        return response($file, 200, [
            'Content-Type' => 'Content-Type: image/png'
        ]);
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥20 求用stm32f103c6t6在lcd1206上显示Door is open和password:
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法