只能访问 Laravel 5.2 中的 / 路由

Posted

技术标签:

【中文标题】只能访问 Laravel 5.2 中的 / 路由【英文标题】:able to access only the / route in Laravel 5.2 【发布时间】:2018-01-01 09:47:34 【问题描述】:

我只能访问“/”路线,而我所有其他路线都返回 404。

我在一个新的 EC2 实例上安装了 laravel,并确保我的 phpmysql 和 apache2 都在运行

我的 Laravel 版本是 5.2.45

我的000-default.conf如下

<VirtualHost *:80>

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/testing/public

        ErrorLog $APACHE_LOG_DIR/error.log
        CustomLog $APACHE_LOG_DIR/access.log combined

</VirtualHost>

我的apache2.conf文件如下

<Directory />
        Options FollowSymLinks
        AllowOverride None
        Require all denied
</Directory>

<Directory /usr/share>
        AllowOverride None
        Require all granted
</Directory>

<Directory /var/www/html/testing/public>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>

我的文件夹结构是 /var/www/html/testing

但我在尝试访问 ip 时得到了 500 分。任何帮助将不胜感激。

routes.php

**********Physiotherapist******/
Route::get('/home-request/physiotherapist', 'HomeController@physiotherapist');
Route::post('/physiotherapist', 'ServicesController@requestPhysio');
Route::post('/physiotherapist/getPhysioRates', 'ServicesController@getPhysioRates');

/********** Doctor *************/
Route::get('/home-request/doctor', 'HomeController@doctor');
Route::post('/doctor', 'ServicesController@requestDoctor');
Route::post('/doctor/getDoctorRates', 'ServicesController@getDoctorRates');

/********** Patient Attendant *************/
Route::get('/home-request/patient-attendant', 'HomeController@patient');
Route::post('/patient', 'ServicesController@requestAttendant');
Route::post('/patient/getPatientAttendantRates', 'ServicesController@getPatientAttendantRates');

/public/.htaccess 文件

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

Options -Indexes


RewriteCond %REQUEST_FILENAME !-f
 RewriteRule ^([^\.]+)$ $1.php [NC,L]
# RewriteRule ^([^\.]+)/([^\.]+)$ /$2.php  [L] 
    # 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>

<ifmodule mod_expires.c>
  ExpiresActive On
  AddType image/x-icon .ico
  ExpiresByType image/gif "access plus 60 days"
  ExpiresByType image/jpeg "access plus 60 days"
  ExpiresByType image/png "access plus 60 days"
  ExpiresByType image/ico "access plus 60 days"
  ExpiresByType image/x-icon "access plus 60 days"
  ExpiresByType text/css "access plus 60 days"
  ExpiresByType application/javascript "access plus 60 days"
  ExpiresByType application/x-javascript "access plus 60 days"
  ExpiresByType text/javascript "access plus 60 days" 
  ExpiresByType application/json "access plus 7 minutes" 
</ifmodule>
## EXPIRES CACHING ##


<IfModule mod_deflate.c>
  # Compress HTML, CSS, JavaScript, Text, XML and fonts
  AddOutputFilterByType DEFLATE application/javascript
  AddOutputFilterByType DEFLATE application/rss+xml
  AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
  AddOutputFilterByType DEFLATE application/x-font
  AddOutputFilterByType DEFLATE application/x-font-opentype
  AddOutputFilterByType DEFLATE application/x-font-otf
  AddOutputFilterByType DEFLATE application/x-font-truetype
  AddOutputFilterByType DEFLATE application/x-font-ttf
  AddOutputFilterByType DEFLATE application/x-javascript
  AddOutputFilterByType DEFLATE application/xhtml+xml
  AddOutputFilterByType DEFLATE application/xml
  AddOutputFilterByType DEFLATE font/opentype
  AddOutputFilterByType DEFLATE font/otf
  AddOutputFilterByType DEFLATE font/ttf
  AddOutputFilterByType DEFLATE image/svg+xml
  AddOutputFilterByType DEFLATE image/x-icon
  AddOutputFilterByType DEFLATE text/css
  AddOutputFilterByType DEFLATE text/html
  AddOutputFilterByType DEFLATE text/javascript
  AddOutputFilterByType DEFLATE text/plain
  AddOutputFilterByType DEFLATE text/xml
    Header append Vary User-Agent
</IfModule>

【问题讨论】:

您能分享routes.php/laravel/public/.htaccess 文件吗? 这里提到了各种方式,查看***.com/questions/13514990/… 我已经更新了相同的..请检查并建议 您的 apache2 日志是否提供任何线索来说明错误是什么? 在 Ubuntu 16.04 中哪里可以找到这个日志文件? 【参考方案1】:

您需要在您的 appache conf 中允许覆盖。试试这个:

<Directory /var/www/html/testing/public>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
</Directory>

【讨论】:

以上是关于只能访问 Laravel 5.2 中的 / 路由的主要内容,如果未能解决你的问题,请参考以下文章

Laravel 5.2 路由仅适用于根目录

laravel 5.2 中特定路由的 web 中间件

在 laravel 5.2 中禁用特定路由的 Web 中间件

Laravel 5.2 中一个路由中的多个路由参数模式

未找到 xampp 对象中的 Laravel 5.2

如何从 db 中的两个表中路由、获取和显示数据到 laravel 5.2 中的单个网页