阿帕奇mod-rewriteLaravel [英] Apache Mod Rewrite For Laravel

查看:247
本文介绍了阿帕奇mod-rewriteLaravel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Laravel对Wampserver安装。目录如下:

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 code

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]

要减少网址

的http://本地主机/ laravel /公/家/指数

但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://本地主机/ laravel /家庭/指数

感谢

推荐答案

在本地测试,我做的两件事情之一。

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的\\ Apache的版本\\的conf \\额外,找到你的的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>
    

    请确保已被列入您的虚拟主机配置文件。打开你的的httpd.conf 文件并搜索虚拟主机文件中,取消了包括行,如果它的注释。然后,我打开命令行,输入记事本C:\\ WINDOWS \\ SYSTEM32 \\ DRIVERS \\ ETC \\主机开辟了您的hosts文件。在其下方提到的项目本地主机将您的新主机。下面是一个例子。

    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 ,你不会有任何恼人的公共目录。这是我如何实现它,因为我preFER的更好看的虚拟主机而不是一个长篇大论本地主机 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.

    希望这有助于。

    这篇关于阿帕奇mod-rewriteLaravel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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