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

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.

主站蜘蛛池模板: 揭阳市| 舞钢市| 永胜县| 宣武区| 西城区| 安达市| 五华县| 正镶白旗| 渝中区| 台北市| 屯门区| 攀枝花市| 庆阳市| 徐水县| 册亨县| 广宗县| 陇西县| 沧源| 那曲县| 台中市| 师宗县| 澎湖县| 天峨县| 堆龙德庆县| 娄底市| 台北县| 罗田县| 麻栗坡县| 肃南| 高邑县| 永川市| 观塘区| 喀喇沁旗| 定襄县| 漳平市| 馆陶县| 贡觉县| 阿城市| 琼中| 东兰县| 南通市|