dongyue7796
2017-11-21 17:39
浏览 43
已采纳

Laravel 5.2访问example.com/而不是共享主机中的example.com/public

so i want to upload my laravel project to shared hosting. After completing it, when i want to access my website (just call it www.example.com) it goes to /public directory and my solution is add route for /public as my homepage but i don't want it.

so here my website path

/
/laravel
/public_html
/tmp

here is my .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]

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

And here is my public_html/index.php

<?php

require __DIR__.'/../laravel/bootstrap/autoload.php';

$app = require_once __DIR__.'/../laravel/bootstrap/app.php';

$app->bind('path.public', function() {
return __DIR__;
});

$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);

$response = $kernel->handle(
    $request = Illuminate\Http\Request::capture()
);

$response->send();

$kernel->terminate($request, $response);

图片转代码服务由CSDN问答提供 功能建议

所以我想将我的laravel项目上传到共享主机。 完成后,当我想访问我的网站(只需将其称为www.example.com)时,它会进入/ public目录,我的解决方案是为/ public添加路由作为我的主页,但我不想要它。

所以我的网站路径

  / 
 / laravel 
 / public_html 
 / tmp 
    
 
 

这是我的.htaccess

 &lt; IfModule mod_rewrite.c&gt; 
&lt; IfModule mod_negotiation.c&gt; 
选项-MultiViews 
&lt  ; / IfModule&gt; 
 
 RewriteEngine On 
 
#重定向尾随斜杠如果不是文件夹... 
 RewriteCond%{REQUEST_FILENAME}!-d 
 RewriteRule ^(。*)/ $ / $ 1 [L,  R = 301] 
 
#句柄前控制器... 
 RewriteCond%{REQUEST_FILENAME}!-d 
 RewriteCond%{REQUEST_FILENAME}!-f 
 RewriteRule ^ index.php [L] 
 
#n 处理授权标题
 RewriteCond%{HTTP:授权}。
 RewriteRule。*  -  [E = HTTP_AUTHORIZATION:%{HTTP:授权}] 
&lt; / IfModule&gt; 
   
 \  n 

这是我的public_html / index.php

 &lt;?php 
 
require __DIR __。'/ .. / laravel / bootstrap / autoload.php'; 
 
 $ app = require_once __DIR __。'/ .. / laravel / bootstrap / app.php  '; 
 
 $ app-&gt; bind('path.public',function(){
return __DIR __; 
}); 
 
 $ kernel = $ app-&gt; make(Illuminate \ Contracts \  Http \ Kernel :: class); 
 
 $ response = $ kernel-&gt; handle(
 $ request = Illuminate \ Http \ Request :: capture()
); 
 
 $ response-&gt;  send(); 
 
 $ kernel-&gt; terminate($ request,$ response); 
   
 
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题