laravel5.* 在本地环境中 会出现路由问题 The requested URL /welcome was not found on this server.

本文详细介绍了在Laravel5.*版本中遇到的路由问题:请求URL未在服务器上找到。问题在于public文件夹缺少.htaccess文件,导致路由无法正确进入虚拟目录。文章提供了具体的解决步骤,包括在public目录下创建.htaccess文件并填写特定代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

laravel5.* 在本地环境中 会出现路由问题: The requested URL /welcome was not found on this server.

经过踩坑,1.重启服务(无效)  2. 清理 laravel 缓存依然无效

最后发现其原因,是在public 文件夹下缺少 .htaccess 文件  路由无法进入虚拟目录中

可按照如下操作解决:

1、public目录下新建一个

public\.htaccess


2、填入下面内容

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>
    RewriteEngine On
    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]
 
    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>
 

http://127.0.0.1:5000/ 显示:“{ "error": "\u8d44\u6e90\u672a\u627e\u5230", "message": "404 Not Found: The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again." }” 小黑窗显示:“ File "E:\Python310\lib\logging\__init__.py", line 1103, in emit stream.write(msg + self.terminator) UnicodeEncodeError: 'gbk' codec can't encode character '\U0001f3e2' in position 46: illegal multibyte sequence Call stack: File "E:\AI_System\agent\agent_core.py", line 24, in <module> from agent.cognitive_architecture import CognitiveArchitecture File "<frozen importlib._bootstrap>", line 1027, in _find_and_load File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed File "<frozen importlib._bootstrap>", line 1027, in _find_and_load File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 688, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 883, in exec_module File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed File "E:\AI_System\agent\__init__.py", line 5, in <module> from .autonomous_agent import AutonomousAgent # 修改此处 File "<frozen importlib._bootstrap>", line 1027, in _find_and_load File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 688, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 883, in exec_module File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed File "E:\AI_System\agent\autonomous_agent.py", line 19, in <module> from core.config import system_config File "<frozen importlib._bootstrap>", line 1027, in _find_and_load File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 688, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 883, in exec_module File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed File "E:\AI_System\core\config.py", line 329, in <module> system_config = CoreConfig() File "E:\AI_System\core\config.py", line 81, in __init__ self.log_config() File "E:\AI_System\core\config.py", line 316, in log_config logger.info("🏢 核心配置摘要:") Message: '🏢 核心配置摘要:' Arguments: () 2025-08-11 21:49:50,262 - CoreConfig - INFO - 🏢 核心配置摘要: 2025-08-11 21:49:50,264 - CoreConfig - INFO - AI系统路径: E:\AI_Workspace 2025-08-11 21:49:50,264 - CoreConfig - INFO - AI系统路径: E:\AI_Workspace 2025-08-11 21:49:50,264 - CoreConfig - INFO - 临时文件路径: E:\AI_Workspace\ai_temp 2025-08-11 21:49:50,264 - CoreConfig - INFO - 临时文件路径: E:\AI_Workspace\ai_temp 2025-08-11 21:49:50,264 - CoreConfig - INFO - 代理路径: E:\AI_System\agent 2025-08-11 21:49:50,264 - CoreConfig - INFO - 代理路径: E:\AI_System\agent 2025-08-11 21:49:50,264 - CoreConfig - INFO - Web UI路径: E:\AI_System\web_ui 2025-08-11 21:49:50,264 - CoreConfig - INFO - Web UI路径: E:\AI_System\web_ui 2025-08-11 21:49:50,264 - CoreConfig - INFO - 模型目录: E:\ai_temp\models 2025-08-11 21:49:50,264 - CoreConfig - INFO - 模型目录: E:\ai_temp\models 2025-08-11 21:49:50,264 - CoreConfig - INFO - 默认模型: qwen2-7b (设备: cpu, 使用GPU: True) 2025-08-11 21:49:50,264 - CoreConfig - INFO - 默认模型: qwen2-7b (设备: cpu, 使用GPU: True) 2025-08-11 21:49:50,264 - CoreConfig - INFO - 日志级别: 20 (日志目录: E:\AI_System\logs) 2025-08-11 21:49:50,264 - CoreConfig - INFO - 日志级别: 20 (日志目录: E:\AI_System\logs) 2025-08-11 21:49:50,265 - CoreConfig - INFO - 熔断阈值: 5 2025-08-11 21:49:50,265 - CoreConfig - INFO - 熔断阈值: 5 2025-08-11 21:49:50,265 - CoreConfig - INFO - ============================================================ 2025-08-11 21:49:50,265 - CoreConfig - INFO - ============================================================ Traceback (most recent call last): File "E:\AI_System\agent\agent_core.py", line 24, in <module> from agent.cognitive_architecture import CognitiveArchitecture File "E:\AI_System\agent\__init__.py", line 5, in <module> from .autonomous_agent import AutonomousAgent # 修改此处 File "E:\AI_System\agent\autonomous_agent.py", line 20, in <module> from core.exceptions import DependencyError, SubsystemFailure ImportError: cannot import name 'SubsystemFailure' from 'core.exceptions' (E:\AI_System\core\exceptions.py) [3/3] 启动用户界面... 系统启动完成!自动打开监控页面... ✅ Eventlet monkey patch applied at startup 2025-08-11 21:49:53 [INFO] WebServer: ================================================== 2025-08-11 21:49:53 [INFO] WebServer: 🚀 开始初始化AI系统 2025-08-11 21:49:53 [INFO] WebServer: ================================================== 2025-08-11 21:49:53 [INFO] WebServer: 项目根目录: E:\AI_System 2025-08-11 21:49:53 [INFO] WebServer: 添加路径: E:\AI_System\agent 2025-08-11 21:49:53 [INFO] WebServer: 添加路径: E:\AI_System\core 2025-08-11 21:49:53 [INFO] WebServer: 添加路径: E:\AI_System\utils 2025-08-11 21:49:53 [INFO] WebServer: 添加路径: E:\AI_System\config 2025-08-11 21:49:53 [INFO] WebServer: 添加路径: E:\AI_System\cognitive_arch 2025-08-11 21:49:53 [INFO] WebServer: 添加路径: E:\AI_System\environment 2025-08-11 21:49:53 [INFO] WebServer: ✅ 模拟AI核心初始化 2025-08-11 21:49:53 [INFO] WebServer: ✅ 模拟硬件管理器初始化 2025-08-11 21:49:53 [INFO] WebServer: ✅ 模拟生活调度器初始化 2025-08-11 21:49:53 [INFO] WebServer: ✅ 模拟AI智能体初始化 2025-08-11 21:49:53 [INFO] WebServer: 环境管理器已启动 2025-08-11 21:49:53 [INFO] WebServer: ✅ 环境管理器初始化成功 2025-08-11 21:49:53 [INFO] WebServer: ✅ 模拟进化监视器启动 2025-08-11 21:49:53 [INFO] WebServer: ✅ 所有系统组件初始化完成 2025-08-11 21:49:53 [INFO] WebServer: ✅ 使用eventlet异步模式 Server initialized for eventlet. 2025-08-11 21:49:53 [INFO] WebServer: 开发服务器运行在 http://0.0.0.0:5000 (14832) wsgi starting up on http://0.0.0.0:5000 ================================================ 运行中进程: python.exe 8532 Console 1 211,552 K python.exe 14832 Console 1 50,572 K ================================================ 按任意键退出此窗口(服务将继续在后台运行)... (14832) accepted ('127.0.0.1', 50710) 127.0.0.1 - - [11/Aug/2025 22:04:34] "GET / HTTP/1.1" 404 340 0.000997 (14832) accepted ('127.0.0.1', 50713) 127.0.0.1 - - [11/Aug/2025 22:04:34] "GET /favicon.ico HTTP/1.1" 404 212 0.001000 127.0.0.1 - - [11/Aug/2025 22:08:27] "GET / HTTP/1.1" 404 340 0.000997 (14832) accepted ('127.0.0.1', 50750)”我应该做什么
最新发布
08-12
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

会飞的小蜗

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值