这是我面临问题的Laravel-5.4代码。我创建了带有两页home &关于我们的的测试laravel项目,并使用Apache v-host(www.test.com)映射了文件路径。
当我按下www.test.com/about www.test.com时,它正确地加载到索引页,但是当我尝试点击时,它显示了404个错误.But,当我按下像这样正确加载url www.test.com页面时,我不知道它的问题是在我的代码或Apache配置中,或者任何其他方面。
控制器:
public function index(){
return view('pages.index');
}
public function about(){
return view('pages.about');
}路线:
// Home Page
Route::get('/','pagesController@index');
// About Us Page
Route::get('/about','pagesController@about'); Apache conf:
ServerAdmin webmaster@localhost
ServerName test.com
ServerAlias www.test.com
DocumentRoot /var/www/html/test/public/.htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>发布于 2017-08-25 12:09:17
您可能对mod_rewrite有一个未启用的问题。
尝试使用a2enmod rewrite启用它,然后重新启动apache /etc/init.d/apache2 restart。
看看那个回答。
或
如果不管用的话。
这可能来自Apache:etc/apache2/httpd.conf。
这个文章会比我解释得更好。
您可能需要编辑:
<Directory "/var/www/html">
...
AllowOverride None
...
</Directory>至
<Directory "/var/www/html">
...
AllowOverride All
...
</Directory>重新启动apache /etc/init.d/apache2 restart
或
如果它仍然不起作用,试着在你的Laravel项目上做一些chmod 0755。
发布于 2017-08-25 12:15:00
在apache上安装和启用了mod_rewrite吗?为了使用mod_rewrite,可以在终端中键入以下命令:
a2enmod rewrite重新启动apache2之后
/etc/init.d/apache2 restart或
service apache2 restart这是我的.htaccess目录中的public/:
<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]
另外,编辑/etc/apache2/sites-enabled/000-default
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>https://stackoverflow.com/questions/45880934
复制相似问题