Zend Framework: The requested URL /newposter was not found on this server.

本文讨论了如何解决在使用Apache服务器时,配置导致无法访问zendframework中的public目录的问题。通过修改httpd-vhosts.conf文件中的AllowOverride设置,确保了虚拟主机能够正确解析请求,并成功访问Controller和action。

Problem:PHP zend framework The requested URL /XXX/public/index was not found on this server 

把根目录指向zend framework中的public目录,因为没有view,直接用Debug Url调试controller和action,一直报“Zend The requested URL /newposter was not found on this server.”这样的错误。

1、首先确定了我的VirtualHost"iphone.com"能够使用。

2、在Controller里面确实存在该action。

3、在httpd-vhosts.conf文件中虚拟主机iphone.com开启了“AllowOverride All”,允许所有具有".htaccess"作用域的指令都允许出现在.htaccess文件中。

4、httpd-vhosts.conf通过在httpd.conf中的“Inlcude /extra/httpd-vhosts.conf”选线启用,打开httpd.conf文件可以发现下面的AllowOverride的选项。

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
</Directory>
#
# Note that from this point forward you must specifically allow
# particular features to be enabled - so if something's not working as
# you might expect, make sure that you have specifically enabled it
# below.
#
#
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "D:\Program Files\Zend\Apache2/htdocs">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.2/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks
    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride None
    #
    # Controls who can get stuff from this server.
    #
    Order allow,deny
    Allow from all
</Directory>

中的AllowOverride为None,直接改为All,重启Appache服务器,能正常访问页面。

参考资料:百度百科--AllowOverride:http://baike.baidu.com/view/9411222.htm

### 404 Not Found 错误翻译及解决方法 #### 含义与翻译 HTTP 状态码 `404 Not Found` 表示客户端能够与服务器通信,但服务器找不到请求的资源。该状态码的中文翻译为“未找到”,通常用于指示请求的页面、文件或 API 接口不存在。在实际应用中,404 错误常被幽默地翻译为“4月4日清明节让你消失”[^1]。 #### 常见原因 - 请求的 URL 输入错误或链接失效。 - 服务器配置错误,例如未正确设置路由或资源路径。 - 应用框架未正确映射资源,如 Spring Boot 项目中未配置 JSP 页面的访问路径[^3]。 #### 解决方法 1. **检查 URL 输入** 用户应确认输入的 URL 是否正确,避免拼写错误或遗漏路径。 2. **检查服务器配置** 若为网站管理员,需确保服务器配置文件中正确设置资源路径,如 Apache 或 Nginx 的虚拟主机配置。 3. **检查应用框架配置** 在 Spring Boot 等框架中,需确保 `application.properties` 或 `web.xml` 中正确配置了 JSP 或静态资源的访问路径。例如,在 Spring Boot 中启用 JSP 访问需添加以下依赖: ```xml <dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> </dependency> ``` 4. **自定义 404 页面** 提供友好的 404 页面不仅能提升用户体验,还能帮助用户反馈错误链接。页面中可包含返回首页的链接、搜索框或错误反馈表单[^4]。 5. **监控与日志分析** 通过服务器日志分析 404 错误来源,识别频繁出现的错误请求,及时修复链接或重定向至正确页面。 #### 示例代码:Spring Boot 自定义错误页面 ```java @Controller public class ErrorController implements org.springframework.boot.web.servlet.error.ErrorController { private static final String PATH = "/error"; @RequestMapping(PATH) public String handleError() { return "custom-404"; // 返回自定义 404 页面 } @Override public String getErrorPath() { return PATH; } } ``` 在 `resources/templates` 目录下创建 `custom-404.html` 页面,用于展示友好的 404 提示信息。 #### 测试 404 页面 为确保 404 页面正常工作,可手动访问不存在的路径,如 `/nonexistent-page`,验证是否跳转至自定义错误页面。 ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值