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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?