xampp apache 重写不起作用 [英] xampp apache rewrite not working

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

问题描述

我在 htdocs 中有一个名为 crm 的文件夹,其中包含一个新的 Laravel 5.1项目,我试图通过 http://localhost/crm/ 访问它但它只是带来包含目录内容的页面索引而不是在我的 routes.php 中映射的页面

I have a folder called crm in htdocs which contains a fresh laravel 5.1 project and i am trying to acess it via http://localhost/crm/ but it just brings the index of page containing the directory contents instead of the page mapped in my routes.php as

Route::get('/', function () {
    return view('panel');
});

我已经检查了 httpd.conf 中是否启用了 apache mod_rewrite

i have checked that apache mod_rewrite is enable in httpd.conf

LoadModule rewrite_module modules/mod_rewrite.so

DocumentRoot "C:/xampp/htdocs"
<Directory "C:/xampp/htdocs">

    Options Indexes FollowSymLinks Includes ExecCGI

    AllowOverride All

    Require all granted
</Directory>

然后crm/public文件夹中的.htaccess文件包含

then the .htaccess file in crm/public folder contains

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

我也试过把它改成

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

没有成功.

推荐答案

您需要将 Laravel 指向 public 目录才能使其工作.例如,如果你已经在 C:/xampp/htdocs/ 目录下安装了 Laravel,你需要使用这些设置:

You need to point Laravel to public directory to make it work. For example, if you've installed Laravel in C:/xampp/htdocs/ directory, you need to use these settings:

DocumentRoot "C:/xampp/htdocs/public"
<Directory "C:/xampp/htdocs/public">

不要在公共文件夹中编辑 .htacces.尝试通过首先转到 localhost 来更改设置并加载 Laravel 网站.

Do not edit .htacces inside public folder. Try to change settings and load Laravel website by going to localhost first.

当您编辑完 Apache 配置文件后,您应该重新启动 Web 服务器.

When you've edited Apache config file, you should restart web server.

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

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