dongqiang5932 2017-08-25 11:59
浏览 352
已采纳

.htaccess设置:Laravel页面重定向无效

Here's is My Laravel-5.4 code that i am facing problem. I had created test laravel project with two pages home & about us and mapped the file path using Apache v-host(www.test.com)
When i hit www.test.com it loads correctly to the index page but when i try to hit www.test.com/about It showing 404 error .But when i hit like this url www.test.com/index.php/about page loads properly I don't know its problem is in my code or Apache configuration or any other

controller:

public function index(){
    return view('pages.index');
}
public function about(){
    return view('pages.about');
}

Route :

// 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>
  • 写回答

2条回答 默认 最新

  • dongzhan3937 2017-08-25 12:09
    关注

    You probably have an issue with mod_rewrite that is not enabled.

    Try to enable it with a2enmod rewrite and then restart apache /etc/init.d/apache2 restart

    Give a look to that answer.

    OR

    If it's not working.
    This may come from Apache conf : etc/apache2/httpd.conf.
    This article will explain it better than me.

    You may need to edit :

    <Directory "/var/www/html">
        ...
        AllowOverride None
        ...
    </Directory>
    

    To

    <Directory "/var/www/html">
        ...
        AllowOverride All
        ...
    </Directory>
    

    And restart apache /etc/init.d/apache2 restart

    OR

    If it's still not working try to do some chmod 0755 on your Laravel's project.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 关于#r语言#的问题:差异分析前数据准备,报错Error in data[, sampleName1] : subscript out of bounds请问怎么解决呀以下是全部代码:
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误