【问题标题】:mod rewrite not working with laravel and bitNamimod rewrite 不适用于 laravel 和 bitNami
【发布时间】:2013-01-25 16:09:18
【问题描述】:

http.conf 有 mod rewrite 未注释

所以没有自定义路线在#laravel 中有人提到这将是因为 mod rewrite 不起作用这里是我的设置:

laravel.conf 有如下代码:

Alias /laravel/ "C:\BitNami/frameworks/laravel/public/"
Alias /laravel "C:\BitNami/frameworks/laravel/public"

<Directory "C:\BitNami/frameworks/laravel/public">
Options +MultiViews
AllowOverride None
<IfVersion < 2.3 >
Order allow,deny
Allow from all
</IfVersion>
<IfVersion >= 2.3>
Require all granted
</IfVersion>
</Directory>

如果我取消注释这些行:

#RewriteEngine On
#RewriteRule ^/$ /laravel/ [PT]

然后主路由将映射到

http://localhost/ 

而不是

http://localhost/laravel 

这是可取的,但次要于主要问题

.htaccess 里面的 public 文件夹有这个:

<IfModule mod_rewrite.c>
    Options +FollowSymLinks
RewriteEngine On
 RewriteBase /laravel
 </IfModule>

 <IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

这是我在 routes.php 中的测试代码:

Route::get('test',function(){
return 'test worked';
});

应该用

解决
http://localhost/laravel/test 

但是我得到一个 404 错误

【问题讨论】:

  • 有同样的问题,不知道如何在Windows下修复它...

标签: apache mod-rewrite wamp laravel bitnami


【解决方案1】:

RewriteBase 和 RewriteEngine 被定义了两次。使您的 .htaccess 文件如下所示:

<IfModule mod_rewrite.c>
    Options +FollowSymLinks
    RewriteEngine On
    RewriteBase /laravel
</IfModule>

<IfModule mod_rewrite.c>
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

如果可能,最好使用 Apache 虚拟主机。

【讨论】:

  • 我有同样的想法,并在这篇文章之前删除了这些行,但我遇到了同样的问题,我已将您的答案复制并粘贴到 laravel 的公共文件夹中的 .htaccess 中,但我仍然有与原始帖子中描述的问题相同
  • 如何添加 Apache 虚拟主机?
  • 我从未使用过 BitNami,只是注意到 .htaccess 文件中有重复项。当我运行 Windows 时,我使用了WampServer。您必须编辑 httpd-vhosts.conf 文件并添加新的站点信息。通常有一个例子。然后在您的 Windows 主机文件 (c:\Windows\System32\drivers\etc\hosts) 中添加 127.0.0.1 example.com
【解决方案2】:

您的 .htaccess 文件应如下所示。

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

    RewriteEngine On

    # Redirect Trailing Slashes...    
    RewriteRule ^(.*)$ public/$1 [L]

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-04
    • 1970-01-01
    • 2012-02-26
    • 1970-01-01
    • 2011-12-05
    • 2018-04-05
    • 2018-03-21
    • 2012-07-21
    相关资源
    最近更新 更多