http.conf 已取消注释 mod 重写
所以没有自定义路由起作用#laravel 中的某人提到这是因为 mod 重写在这里不起作用是我的设置:
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
这是更可取的,但对于主要问题来说是次要的
公共(public)文件夹内的.htaccess有这样的:
<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 错误
最佳答案
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 虚拟主机。
关于apache - mod 重写不适用于 laravel 和 bitNami,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14797206/