官术网_书友最值得收藏!

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:

  1. 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>
  2. 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.

主站蜘蛛池模板: 怀柔区| 柳江县| 普兰店市| 建德市| 凤阳县| 桐城市| 云南省| 陕西省| 增城市| 遵义县| 彭水| 隆林| 鹤岗市| 西乌珠穆沁旗| 涪陵区| 辽中县| 枝江市| 裕民县| 安国市| 常宁市| 泽州县| 诏安县| 卢龙县| 镇平县| 马关县| 澎湖县| 乐安县| 永德县| 嘉义县| 高唐县| 定日县| 额敏县| 云阳县| 大姚县| 佛坪县| 青海省| 赞皇县| 四平市| 隆化县| 张家川| 巩留县|