- 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.
推薦閱讀
- Cisco OSPF命令與配置手冊
- Truffle Quick Start Guide
- Hands-On Industrial Internet of Things
- 新一代物聯(lián)網(wǎng)架構(gòu)技術(shù):分層算力網(wǎng)絡
- 信息通信網(wǎng)絡建設安全管理概要2
- 網(wǎng)絡的琴弦:玩轉(zhuǎn)IP看監(jiān)控
- Spring 5.0 Projects
- 5G時代的大數(shù)據(jù)技術(shù)架構(gòu)和關鍵技術(shù)詳解
- 數(shù)字王國里的虛擬人:技術(shù)、商業(yè)與法律解讀
- 國外物聯(lián)網(wǎng)透視
- Scala Programming Projects
- 網(wǎng)絡是怎樣連接的
- 計算機網(wǎng)絡(項目教學版)
- 移動應用開發(fā)技術(shù)
- 計算機聯(lián)鎖及信號微機監(jiān)測系統(tǒng)