在你下了 Yii 框架,配置完路由 urlManager 后,路由访问页面会报错“the requested URL was not found on this server”,url类似于这种“https://www.cnblogs.com/site/index”。

 'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,//不显示.php
'suffix' => '.html',//后缀
'rules' => [
"<controller:\w+>/<action:\w+>/<id:\d+>"=>"<controller>/<action>",
"<controller:\w+>/<action:\w+>"=>"<controller>/<action>"
],
],

解决方法:

方法一:删除项目下的 runtime 文件夹,然后强刷页面。

方法二:在项目文件夹下面添加 “.htaccess”文件,内容如下:

Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on # if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d # otherwise forward it to index.php
RewriteRule . index.php

或者这个也可以(两个选一个)

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

添加以后再刷新页面,就会发现可以正常访问了,完美解决。

什么是 .htaccess?

.htaccess是一个纯文本文件,它里面存放着Apache服务器配置相关的指令。

当我们使用apache部署一个网站代码准备部署到网上的时候,我们手中的apache的httpd.conf大家肯定都知道。这是apache的配置文件,然而我们大多数的网站都是基于云服务器来部署的,还有就是团队协作开发的时候,我们很难直接修改公共的httpd.conf,这时 .htaccess就是httpd.conf的衍生品,它起着和httpd.conf相同的作用。

.htaccess 的作用?

  • URL重写、自定义错误页面

  • MIME类型配置

  • 访问权限控制等

  • 主要体现在伪静态的应用

  • 图片防盗链

  • 自定义404错误页面

  • 阻止/允许特定IP/IP段

  • 目录浏览与主页

  • 禁止访问指定文件类型

  • 文件密码保护

Yii2.0 解决“the requested URL was not found on this server”问题的更多相关文章

  1. php ci 报错 Object not found! The requested URL was not found on this server. If you entered the URL manually please check

    Object not found! The requested URL was not found on this server. The link on the referring page see ...

  2. 404 Not Found The requested URL * was not found on this server

    1. 把从SVNcheckout下来的代码搭建起来.CakePHP+mysql.改动数据库配置. 2. 配置虚拟主机,发现訪问不了/user/login这个URL,报这个错误:404 Not Foun ...

  3. Not Found The requested URL / was not found on this server.

    http://www.wanysys.cc/coding/php/800.html 今天在做本地PHP项目的时候,想把之前wampserver的本地虚拟服务器环境访问方式改为本地localhost访问 ...

  4. Object not found! The requested URL was not found on this server.... 报错解决方案

    服务器(centos6.5) lnmp 报错如下 Object not found! The requested URL was not found on this server. The link ...

  5. The requested URL / was not found on this server——Apache配置虚拟域名后无法访问localhost

    今天为了做项目,在Apache中配置了项目域名,成功访问.但是忽然发现要访问localhost突然出现The requested URL / was not found on this server. ...

  6. The requested URL / was not found on this server

    The requested URL / was not found on this server.原因:未打开Apache的重写功能#LoadModule rewrite_module modules ...

  7. wampserver 的Apache启动错误提示:The requested URL / was not found on this server.

    打开localhost显示以下错误 原因:之前我配置了虚拟主机,所以服务器是从虚拟环境访问的,localhost也就访问不到 解决方法:打开httpd.conf配置文件,将Include conf/e ...

  8. EasyUI Tabs + Yii2.0实现iframe方式打开页面(解决共用静态文件引入加载的问题)

    在项目实际开发中,有将打开的各个链接页面隔离的需求(防止静态资源起冲突),这个时候常规思路就是使用iframe来实现!但遇到一个比较棘手的问题,当用easyui Tabs打开一个iframe页面时,怎 ...

  9. yii2.0高级框架配置时打开init.bat秒退的解决方法 (两种方法)

    第一种: 这几天刚接触到yii2.0框架,在配置advanced版本时运行init.bat初始化文件时老是闪退: 用cmd运行该文件时显示:The OpenSSL PHP extension is r ...

随机推荐

  1. 当map遇到parseInt

    也是一道面试题,估计除了面试题,一般情况下,也不会写出类似的代码了. ['1', '2', '3'].map(parseInt) 这么一道题的返回结果是什么? 如果不用浏览器去验证,乍一看,似乎确实没 ...

  2. 稀疏矩阵 part 1

    ▶ 图片参考[http://www.bu.edu/pasi/files/2011/01/NathanBell1-10-1000.pdf] ▶ 各种系数矩阵的数据结构 ● MAT,原始矩阵数据 type ...

  3. 用tar命令把目标压缩包解压到指定位置

    linux下tar命令解压到指定的目录 : #tar zxvf /bbs.tar.zip -C /zzz/bbs    //把根目录下的bbs.tar.zip解压到/zzz/bbs下,前提要保证存在/ ...

  4. resin4.0服务器远程调试说明

    1.开发环境介绍: 目前dev用resin 作为服务容器.服务调用之间过于复杂,要进行本地代码调试过于复杂,甚至无法进行.但是可以通过jvm的远程代码调试来达到本地代码调试的目的,步骤如下. 2.re ...

  5. FutureTask原理解析

    原文链接:http://www.studyshare.cn/blog-front/blog/details/1130 首先写一个简单的Demo public static void main(Stri ...

  6. 触摸事件,手势识别(UITouch,UIGestureRecognizer)

    触摸发生时,UIWindow会有一个队列来存放所有的触摸事件,然后再把这些事件发送给对应的hit-test view,hit-test view会通过touch的四个函数来接收这些事件. 四个函数分别 ...

  7. ruby在index页面显示货币符号

    1.显示人民币符号 <td><%= number_to_currency product.price, unit: "¥" %></td> 2. ...

  8. jquery中添加元素append,prepend,before和after方法的区别

    append:在元素内部的最后面添加元素,作为子元素. prepend:在元素内部的最前面添加元素,作为子元素. before:在元素的前边,作为兄弟元素添加. after:在元素的后边,作为兄弟元素 ...

  9. Arthas的基础学习

    下载与安装 wget https://alibaba.github.io/arthas/arthas-boot.jar java -jar arthas-boot.jar 启动 查看启动的帮助信息: ...

  10. 关于第一个launcher开发笔记

    本笔记主要记录阅读关于launcher代码是的相关知识点. viewpager的简单使用(适配器模式):https://www.cnblogs.com/fuly550871915/p/4922953. ...