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

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.

主站蜘蛛池模板: 肥西县| 卓资县| 亳州市| 禄劝| 德庆县| 汝南县| 天峻县| 阳新县| 同德县| 黄梅县| 恩施市| 峨山| 峡江县| 方正县| 丹东市| 林芝县| 得荣县| 聊城市| 宜川县| 敦化市| 凤冈县| 阿拉善右旗| 昌黎县| 修文县| 金平| 定西市| 延边| 辛集市| 佳木斯市| 塔河县| 上栗县| 浏阳市| 利津县| 于田县| 安西县| 沙洋县| 广饶县| 双江| 赫章县| 睢宁县| 伽师县|