Apache Mod 重写 Laravel [英] Apache Mod Rewrite For Laravel

查看:15
本文介绍了Apache Mod 重写 Laravel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Wampserver 上安装了 Laravel.目录如下:

I have an installation of Laravel on Wampserver. The directory is as follows:

C:\wamp\www\laravel

C:\wamp\www\laravel

现在网址是这样的:

http://localhost/laravel/public/index.php/home/index

所以我使用了下面的htaccess代码

So I used the following htaccess code

Options +FollowSymLinks
Options -indexes
DirectoryIndex index.PHP
RewriteEngine on
RewriteCond $1 !^(index\.PHP|images|robots.txt)
RewriteCond %{REQUEST_ FILENAME} !-f
RewriteCond %{REQUEST_ FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L, QSA]

将 URL 缩减为

http://localhost/laravel/public/home/index

但是 Laravel 框架坚持所有应用程序文件都驻留在公共文件夹中.

But the laravel framework insists that all application files reside in the public folder.

所以我想知道我需要在 htaccess 文件中添加(或减去)什么,以便 URL 看起来像

So I would like to know what I need to add to (or subtract from) the htaccess file so that the URL can look like

http://localhost/laravel/home/index

谢谢

推荐答案

在本地测试时,我会做两件事之一.

When testing locally I do one of two things.

  1. 使用以下内容在公共目录下创建一个新的 .htaccess.

  1. Create a new .htaccess below the public directory with the following.

<IfModule mod_rewrite.c>
    RewriteEngine on

    RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

  • 创建一个新的虚拟主机.使用 WAMP,您可以导航到 C:\wamp\bin\apache\YOUR APACHE VERSION\conf\extra 并找到您的 httpd-vhosts.conf 文件,在那里您可以请参阅示例虚拟主机.这是我的一个:

  • Create a new virtual host. With WAMP you can navigate to C:\wamp\bin\apache\YOUR APACHE VERSION\conf\extra and find your httpd-vhosts.conf file, in there you can see example virtual hosts. Here's one of mine:

    <VirtualHost *:80>
        DocumentRoot "c:/wamp/www/laravel/public"
        ServerName laravel.dev
        ServerAlias www.laravel.dev
    </VirtualHost>
    

    确保包含您的 vhosts 配置文件.打开你的 httpd.conf 文件并搜索 vhosts 文件,如果它被注释掉,取消注释包含行.然后我打开 CLI 并输入 notepad "C:\windows\system32\drivers\etc\hosts" 这会打开你的主机文件.在提到 localhost 的项目下面放置您的新主机.这是一个例子.

    Make sure that your vhosts configuration file is being included. Open up your httpd.conf file and search for the vhosts file, uncomment the include line if it's commented out. Then I open the CLI and enter notepad "C:\windows\system32\drivers\etc\hosts" which opens up your hosts file. Underneath the item that mentions localhost place your new host. Here's an example.

    127.0.0.1  laravel.dev
    

    确保您重新启动 Apache 和宾果游戏,您应该能够导航到 http://laravel.dev 并且您不会有任何烦人的公共目录.这就是我实现它的方式,因为我更喜欢看起来更好看的虚拟主机,而不是冗长的 localhost URL.

    Make sure you restart Apache and bingo, you should be able to navigate to http://laravel.dev and you won't have any annoying public directory. This is how I achieve it, as I prefer the nicer looking virtual host rather then a long winded localhost URL.

    希望这会有所帮助.

    这篇关于Apache Mod 重写 Laravel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆