- 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.
推薦閱讀
- 網(wǎng)絡(luò)教育學(xué)習(xí)指導(dǎo)
- MERN Quick Start Guide
- Truffle Quick Start Guide
- 計算機(jī)網(wǎng)絡(luò)安全實(shí)訓(xùn)教程(第二版)
- 互聯(lián)網(wǎng)基礎(chǔ)資源技術(shù)與應(yīng)用發(fā)展態(tài)勢(2021—2023)
- 面向物聯(lián)網(wǎng)的嵌入式系統(tǒng)開發(fā):基于CC2530和STM32微處理器
- 互聯(lián)網(wǎng)安全的40個智慧洞見:2014年中國互聯(lián)網(wǎng)安全大會文集
- 物聯(lián)網(wǎng)與無線傳感器網(wǎng)絡(luò)
- 物聯(lián)網(wǎng)長距離無線通信技術(shù)應(yīng)用與開發(fā)
- 6G無線網(wǎng)絡(luò)空口關(guān)鍵技術(shù)
- Dart Cookbook
- LwIP應(yīng)用開發(fā)實(shí)戰(zhàn)指南:基于STM32
- Intelligent Mobile Projects with TensorFlow
- Python API Development Fundamentals
- 信息技術(shù)安全評估準(zhǔn)則:源流、方法與實(shí)踐