伙计们,我花了六个小时试图解决这个问题。每次我尝试访问一条路线时,我都会得到
"The requested URL was not found on this server."
,除了 "/"
路线。如果我将 web.php
上的其他路线更改为 "/"
,它就可以工作。
这是 apache 的
default.conf
:
<VirtualHost *:80>
ServerName website-project
DocumentRoot /var/www/website-project/public
<Directory /var/www/website-project>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
这是
.htaccess
文件:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
这是我的 url 变量
.env
:
APP_URL=http://localhost:8080
这些是
web.php
的路线:
Route::get('/create', [AppointmentController::class, 'newAppointment'])->name('appointment.newAppointment');
Route::post('/create', [AppointmentController::class, 'createAppointment'])->name('appointment.createAppointment');
Route::get('/edit/{appointment}', [AppointmentController::class, 'editAppointment'])->name('appointment.editAppointment');
Route::get('/', [AppointmentController::class, 'index'])->name('appointment.index');
我应该注意,我正在
php:8.0-apache
容器上运行服务器。
我尝试过:
mod_rewrite
。显然已经开启了。RewriteCond
和 RewriteRule
。php artisan route:clear
和 php artisan config:clear
。"/"
,任何内容都可以工作。如果有人在挣扎,我必须把
RUN a2enmod rewrite | service apache2 restart
在apache的dockerfile
的最后一行,因为在容器的bash中运行它是行不通的,因为你需要重新启动服务器,从而擦除更改。