简体   繁体   English

Laravel URL重写

[英]Laravel URL Rewrite

To go directly to the controller on my laravel access by accessing : 通过访问以下命令直接进入我的laravel访问控制器:

http://localhost/laravel/public/home

Do i have to dont use /public ? 我不必使用/ public吗? Can I just use : 我可以使用:

http://localhost/laravel/home

Is this because the directory is on the public folder that causes this and should be like this? 这是因为目录位于导致此问题的公用文件夹上,并且应该像这样吗?

Thanks 谢谢

Depends where your instance of Laravel is located, and whether rewrite rules have been set. 取决于您的Laravel实例位于何处,以及是否设置了重写规则。

Assuming your Apache/nginx document root is /my/dir/ and your public folder is /my/dir/public/ (which makes the Laravel directory /my/dir/laravel/), you will need the /public/. 假设您的Apache / nginx文档根目录为/ my / dir /,公共文件夹为/ my / dir / public /(这使Laravel目录为/ my / dir / laravel /),则需要/ public /。

However, if your root dir is /my/dir/ and your laravel folder is in /my/laravel/, you can rename public to dir and skip using the public part, as it is now mapped to the documentRoot for the webserver. 但是,如果您的根目录为/ my / dir /,而laravel文件夹位于/ my / laravel /中,则您可以将public重命名为dir并跳过public部分,因为它现在已映射到Web服务器的documentRoot。

You can change all the paths in multiple places: 您可以在多个位置更改所有路径:

  • The locations of the paths.php file (which defines all the other paths) is in index.php in your public folder paths.php文件的位置(定义了所有其他路径)在公用文件夹的index.php中。
  • The location of all the other paths is defined in paths.php , one by one. 所有其他路径的位置在paths.php中一一定义。 The public one is $paths["public"]. 公开的是$ paths [“ public”]。 You can change this to anything you like and it will impact both Laravel and the Artisan CLI interface. 您可以将其更改为任何您喜欢的名称,这将影响Laravel和Artisan CLI界面。 Bear in mind that Laravel does a small directory transformation after the variable is set (still in that file). 请记住,在设置变量后(仍然在该文件中),Laravel进行了小的目录转换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM