修改XAMPP端口至8000后Laravel虚拟主机路由访问错误求助
Hey there, let's get this sorted out for you! The main issue here is how you're formatting your URLs—you've got the port number in the wrong spot.
What's Wrong with Your Current URLs?
When you try to visit http://laravel.test/about:8000/ or http://laravel.test/homepage:8000/, your browser interprets about:8000 and homepage:8000 as part of the path, not the port number. That's why you're hitting errors.
Correct URL Format
Port numbers always go right after the domain name, separated by a colon, before the route path. So your valid URLs should be:
http://laravel.test:8000/abouthttp://laravel.test:8000/homepage
Double-Check These Configs to Avoid Other Issues
If you still run into problems after fixing the URL format, verify these settings:
Apache Port Configuration:
Open XAMPP's Apachehttpd.conffile and make sure theListendirective is set to 8000:Listen 8000Then check your
httpd-vhosts.conffile (usually inxampp/apache/conf/extra/) to ensure your virtual host uses port 8000:<VirtualHost *:8000> DocumentRoot "C:/xampp/htdocs/your-laravel-project/public" ServerName laravel.test ErrorLog "logs/laravel.test-error.log" CustomLog "logs/laravel.test-access.log" common </VirtualHost>Hosts File Setup:
Make sure your local hosts file mapslaravel.testto127.0.0.1:- On Windows: Edit
C:\Windows\System32\drivers\etc\hostsand add127.0.0.1 laravel.test - On Mac/Linux: Edit
/etc/hostsand add127.0.0.1 laravel.test
- On Windows: Edit
Laravel Route Configuration:
Confirm your routes inroutes/web.phpare correctly defined (no typos!). For example:Route::get('/about', function () { return view('about'); }); Route::get('/homepage', function () { return view('homepage'); });Restart Apache:
After making any configuration changes, restart the Apache service in XAMPP to apply the updates.
Once you've fixed the URL format and verified these settings, your routes should load without errors!
内容的提问来源于stack exchange,提问作者Evan

