我正在使用laravel 4。
我有一个视图nest.blade.php和相应的控制器NestController.php:
控制器内容:
class NestController extends BaseController {
public function showView()
{
return View::make('nest');
}
}
路线:
Route::get('/nest', 'NestController@showView');
当我去网址/嵌套它不起作用。
当我转到url / index.php / nest时,它确实起作用。
显然,我只希望它不带index.php即可。
我该如何解决?
我的htaccess:
IfModule mod_rewrite.c>
Options -MultiViews
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]
根据您的.htaccess文件,您似乎正在运行Laravel 4.1? 无论如何,我将您的路由和控制器复制到了我的环境(4.0和4.1)中,并且所有内容都可以通过nest url正常运行。 这些都没错。
有趣。 我的虚拟主机有什么关系吗? 还是我在安装过程中没有做一些使路由正常工作的事情? 正在思考所有这些可能性。 是的,我正在运行最新版本。
是的,我会调查这些,但不幸的是,这超出了我的了解。 就像我说的,一切都可以在我的环境中与您的route.php,controller甚至.htaccess完美配合。 我的apache2使用所有默认设置运行,因此那里也不需要任何特殊设置。
漂亮的网址
The framework ships with a public/.htaccess file that is used to allow
URLs without index.php. If you use Apache to serve your Laravel
application, be sure to enable the mod_rewrite module.
如果Laravel随附的.htaccess文件不适用于您的
Apache安装,请尝试以下一项:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
如需更多相关帮助,请查看此答案。
我会尽快收到您的答复,谢谢。 对于其他人,不要使用上面的代码,答案在链接中,我不得不对a2enmod进行了重写
@TheAlpha伙计,这花了我大约4个小时。 终于成功了! 谢谢!!
@JoshHarington,很高兴您终于做到了:-)
我在Apache HTTP服务器中启用了mod_rewrite模块,重新启动了Apache服务,并再次进行了测试,结果正常!!!
下面是我用来启用mode_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>
我用于ubuntu服务器cd / etc / apache2; 苏多苏; vim apache2.conf; 并且我添加了选项索引FollowSymLinks MultiViews AllowOverride All允许,拒绝所有 Directory>
将httpd.conf中的AllowOverride None行更改为AllowOverride All时,请确保在包含有效路径的内部执行。
例
#check path Options Indexes FollowSymLinks
AllowOverride All
没错,请仅在我们特定的Web内容目录(例如上面的代码)中而不是在 Directory>部分/块中应用语句" AllowOverride All"。 它在httpd.conf注释中明确提到。
注意!如果即使启用重写模块后仍无法正常工作。您需要将httpd.conf中的" AllowOverride None"行更改为" AllowOverride All"。
正如@Alpha提醒的那样,不需要为此配置Laravel。
由于某些原因,以上答案对我不起作用,因此这是唯一对我有用的答案。
我正在使用ubuntu 18.04 amd64作为开发服务器环境。
所以我修改了位于/etc/apache2的apache.conf文件
From:
blockquote>
Options Indexes FollowSymLinks AllowOverride None Require all granted
To:
blockquote>
Options Indexes FollowSymLinks AllowOverride All Require all granted
And Also From:
blockquote>
AllowOverride None Require all granted
To
blockquote>
AllowOverride All Require all granted
之后,您需要在终端中使用sudo service apapche2 restart命令重新启动apache
现在,我无需使用URL中的index.php就可以访问页面
感谢:joshymatheww @ Laracasts服务器上的讨论频道
2017年8月5日
在您的.htaccess中设置
DirectoryIndex index.php
Options -MultiViews
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]
登录终端
sudo nano /etc/apache2/apache2.conf
下线后
.
.
.
并粘贴下面的代码
Options Indexes FollowSymLinks MultiViews
AllowOverride All
现在按Ctrl + O,然后按Ctrl + M,再按Ctrl + x
现在重新启动apache服务器
sudo service apache2 restart