Tôi mới đến ấu trùng. Tôi đang sử dụng Ubuntu 15.04. Tôi đã cài đặt Laravel Framework phiên bản 5.1.7 (LTS) bằng cách sử dụng nhà soạn nhạc và một máy chủ đèn sử dụng lệnh $ sudo apt-get install lamp-server^
(Tôi đã không cài đặt Homestead). Tôi đang sử dụng PhpStorm 8.0.3
làm IDE.laravel 5 chỉ hoạt động tuyến đường gốc
Tôi đã tạo ba tuyến đường và một bộ điều khiển. Các tập tin PagesController.php
trông như thế này:
class PagesController extends Controller
{
public function index()
{
return 'Welcome to my homepage!';
}
public function about()
{
return 'Learn a little about me.';
}
public function hello()
{
return 'Hello World!';
}
}
và routes.php
trông như thế này:
Route::get('/', '[email protected]');
Route::get('about', '[email protected]');
Route::get('hello', '[email protected]');
Bất cứ khi nào tôi đi đến http://localhost:63342/my-first-app/public/
(hoặc http://localhost:63342/my-first-app/public/index.php
) nó hoạt động tốt và tôi thấy thông điệp Welcome to my homepage!
. Nhưng bất cứ khi nào tôi truy cập http://localhost:63342/my-first-app/public/hello
hoặc http://localhost:63342/my-first-app/public/about
, nội dung tôi nhận được là thông báo 404 Not Found
.
Ngoài ra, .htaccess
tập tin được đặt tại my-first-app/public
trông như thế này:
<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]
</IfModule>
Những gì tôi đã cố gắng:
- tôi đã cố gắng
http://localhost:63342/my-first-app/public/index.php/hello
hoặchttp://localhost:63342/my-first-app/public/index.php/about
nhưng nó không hoạt động nữa. - Tôi đã nhập lệnh
sudo a2enmod rewrite
theo sau làsudo service apache2 restart
nhưng không hoạt động. - Tôi đã thử
composer dump-autoload
nhưng không hoạt động. Tôi đã thay đổi
AllowOverride
từNone
thànhAll
trongapache2.conf
. Bây giờ một phần của nó trông giống như sau:<Directory /> Options FollowSymLinks AllowOverride All Require all denied </Directory> <Directory /usr/share> AllowOverride All Require all granted </Directory> <Directory /var/www/> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> <Directory /srv/> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory>
nhưng cũng không giải quyết được sự cố.
Cập nhật (2015/07/15):
Kết quả của việc chạy php artisan route:list
trông như thế này:
+--------+----------+-------+------+--------------------------------------------+------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+----------+-------+------+--------------------------------------------+------------+
| | GET|HEAD |/ | | App\Http\Controllers\[email protected] | |
| | GET|HEAD | about | | App\Http\Controllers\[email protected] | |
| | GET|HEAD | hello | | App\Http\Controllers\[email protected] | |
+--------+----------+-------+------+--------------------------------------------+------------+
Chạy "đường dẫn nghệ nhân php: danh sách" và dán đầu ra. Bạn sẽ thấy tất cả các tuyến đường được xác định ở đó. –
@ jedrzej.kurylo Cảm ơn bạn đã trả lời. Tôi đã thêm kết quả vào cuối câu hỏi của mình. – today
Bạn có thể thêm dd ('test') hay không; ở đầu tệp chỉ mục của bạn, đi tới "http: // localhost: 63342/my-first-app/public/index.php/about" và xem thử nghiệm có được xuất không? bằng cách này chúng ta sẽ biết nếu đó là một cái gì đó với viết lại hoặc với mã Laravel –