我正在使用laravel 4。
我有一个视图nest.blade.php
和相应的控制器NestController.php:
控制器内容:
class NestController extends BaseController {
public function showView()
{
return View::make('nest');
}
}
路线:
Route::get('/nest', 'NestController@showView');
当我去url / nest它不起作用。当我去url / index.php / nest时,它确实有效。
显然我只想让它成为/ nest而不使用index.php。
我该如何解决这个问题?
我的htaccess:
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>
该框架附带一个public / .htaccess文件,用于允许没有index.php的URL。如果您使用Apache来为Laravel应用程序提供服务,请确保启用mod_rewrite模块。
如果Laravel附带的.htaccess
文件不能与您的Apache安装一起使用,请尝试以下方法:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
有关更多相关帮助,请查看this answer。
我在Apache HTTP服务器中启用了mod_rewrite模块,重新启动了Apache服务并再次进行了测试并且工作正常!
下面是我用来启用mod_rewrite的代码;
1)在Apache / conf / httpd.conf中取消哈希这一行
LoadModule rewrite_module modules / mod_rewrite.so
2)为“sample-project”创建新配置,而不修改httpd.conf文件中的默认配置
Directory "C:/Apache24/htdocs/sample-project"> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny Allow from all Directory>
注意!如果启用重写模块后仍无法正常工作。您需要在httpd.conf中将“AllowOverride None”行更改为“AllowOverride All”。
当@The Alpha警告时,Laravel不需要为此目的进行配置。
当您在AllowOverride None
中将AllowOverride All
行更改为httpd.conf
时,请确保在包含有效路径的<directory ...>
中执行此操作。
例
<Directory "/var/www/html"> #check path
Options Indexes FollowSymLinks
AllowOverride All
</Directory>
在你的.htaccess中设置它
DirectoryIndex index.php
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^index\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteRule .? %{ENV:BASE}/index.php [L]
由于某些原因,上面的答案对我不起作用,所以这里唯一适合我的答案。
我使用ubuntu 18.04 amd64
作为我的开发服务器环境。所以我修改了位于atapache.conf
的/etc/apache2
文件
从:
<Directory /var/www/> Options Indexes FollowSymLinks AllowOverride None Require all granted
至:
<Directory /var/www/> Options Indexes FollowSymLinks AllowOverride All Require all granted
还来自:
<Directory /usr/share> AllowOverride None Require all granted
至
<Directory /usr/share> AllowOverride All Require all granted
之后,您需要在终端中使用apache
命令重新启动sudo service apapche2 restart
现在我可以在不使用URL中的index.php的情况下访问该页面
归功于:joshymatheww @ Laracasts servers discussion channel on Aug 5, 2017