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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀