- Laravel Application Development Cookbook
- Terry Matula
- 163字
- 2021-07-23 15:33:31
Creating "clean" URLs
When installing Laravel, the default URL we will use is http://{your-server}/public
. If we decide to remove /public
, we can use Apache's mod_rewrite
to change the URL.
Getting ready
For this recipe, we just need a fresh installation of Laravel and everything running on a properly configured Apache server.
How to do it...
To complete this recipe, follow these steps:
- In our app's root directory, add a
.htaccess
file and use this code:<IfModule mod_rewrite.c> RewriteEngine On RewriteRule ^(.*)$ public/$1 [L] </IfModule>
- Go to
http://{your-server}
and view your application.
How it works...
This simple bit of code will take anything we add in the URL and direct it to the public
directory. That way, we don't need to manually type in /public
.
There's more...
If we decide to move this application to a production environment, this is not the best way to accomplish the task. In that case, we would just move our files outside the web root and make /public
our root directory.
推薦閱讀
- SOA用戶指南
- OpenLayers Cookbook
- Learning QGIS 2.0
- Web Application Development with R Using Shiny
- 局域網組建、管理與維護項目教程(Windows Server 2003)
- 雷達饋線技術
- 物聯網長距離無線通信技術應用與開發
- Practical Web Penetration Testing
- 5G技術核心與增強:從R15到R17
- 中國互聯網發展報告2021
- 華為HCIA-Datacom認證指南
- 物聯網與智慧農業
- Professional Scala
- 智能物聯網:區塊鏈與霧計算融合應用詳解
- Architecting Data:Intensive Applications