doushi7761 2015-08-25 07:31
浏览 146
已采纳

Laravel 5.1 - 删除方法绑定URL的“public /”?

I need some help Please, for I'm beginner with Laravel and MVC. I want to remove the "public/" of the URL.

The only two "solutions" that I found in Google, are: Either with .htaccess. But with me (and obviously not with me) it's not working. Either by putting what is in the "public" folder at the root of the project Laravel. This is not good for security reasons.

There is a real solution to remove the "public/" URL? So that for example this URL:

localhost/Laravel/public/test

Accessible only with this URL:

localhost/Laravel/test

Because if it or has no solution, it is of no use that I continuous to take courses on this Frameworks.

_I had read, that there may be a solution with this in AppServiceProvider:

http://www.creerwebsite.com/medias/upload/larav2.png

Or with this in the Router or a container:

App::bind('path.public', function() {
return base_path().'/public_html';

});

But I am beginner, so I do not find the solution.

Thank you.

  • 写回答

2条回答 默认 最新

  • doushi3189 2015-08-25 08:36
    关注

    The best option is to configure your local installation of WAMP to use Laravel's public folder as the document root. You have two options here:

    Option 1. Use wamp just for this project alone

    1. Find your httpd.conf file. This is the server config, and should be located in C:\wamp\bin\apache\Apache2.4.4\conf. (it's a good idea to make a backup of this file before editing)
    2. Open the config file in notepad, find the line DocumentRoot "c:/wamp/www" and change to DocumentRoot "c:/wamp/www/public" (assuming you have your laravel project in the www folder)
    3. save the httpd.conf and restart wamp.

    Now when you visit http://localhost you should see the Laravel welcome screen.

    Option 2. Set up a virtual host

    This option is a bit more complicated, but will allow you to have multiple websites running alongside each other in wamp, each with their own subdomain that you can use to access them in your browser.
    1. open the httpd.conf file in notepad and find the line DocumentRoot "c:/wamp/www". Change it to DocumentRoot "c:/wamp/www/default".
    2. add the following snippet below this line:

    NameVirtualHost 127.0.0.1
    <VirtualHost 127.0.0.1>
        ServerName localhost
        DocumentRoot 'c:/wamp/www'
    </VirtualHost>
    
    <VirtualHost 127.0.0.1>
        ServerName myproject.localhost
        DocumentRoot 'c:/wamp/www/myproject/public'
    </VirtualHost>
    

    This will create two new virtual hosts running on your local ip. One will work on the domain localhost and serve files from the www/default folder, the other will work on the domain myproject.localhost and serve files from the www/myproject/public folder.

    1. locate your hosts file at C:\Windows\System32\drivers\etc and open it in notepad. add the following lines:
      127.0.0.1 localhost
      127.0.0.1 myproject.localhost
      This will add two domain mappings that point traffic to your local ip for wamp to handle.

    2. Now navigate to the www folder and create C:\wamp\www\default and C:\wamp\www\myproject. Move your laravel project into the \myproject folder ensuring that the public folder is here as well.

    3. finally restart wamp and now you should be able to go to http://myproject.localhost and see your laravel website.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。