Url的重写

nginx的配置文件

  1. [root@localhost protected]# vim /etc/nginx/conf.d/default.conf
  2. server {
  3. listen       80;
  4. server_name  localhost;
  5. #charset koi8-r;
  6. #access_log  /var/log/nginx/log/host.access.log  main;
  7. location = /favicon.ico {
  8. log_not_found off;
  9. access_log off;
  10. }
  11. location = /robots.txt {
  12. allow all;
  13. log_not_found off;
  14. access_log off;
  15. }
  16. location / {
  17. try_files $uri $uri/ /index.php?$args;
  18. if (!-e $request_filename){
  19.              rewrite ^/(.*)$ /index.php?r=$1 last;
  20.         }
  21. root   /usr/share/nginx/html;
  22. index  index.php  index.html  index.htm;
  23. }
  24. location ~ /(protected|framework|nbproject|themes/\w+/views|index-test\.php) {
  25. deny all;
  26. # for production
  27. internal;
  28. log_not_found off;
  29. access_log off;
  30. }
  31. #error_page  404              /404.html;
  32. # redirect server error pages to the static page /50x.html
  33. #
  34. error_page   500 502 503 504  /50x.html;
  35. location = /50x.html {
  36. root   /usr/share/nginx/html;
  37. }
  38. # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  39. #
  40. #location ~ \.php$ {
  41. #    proxy_pass   http://127.0.0.1;
  42. #}
  43. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  44. #
  45. location ~ \.php$ {
  46. root           /usr/share/nginx/html;
  47. include  fastcgi_params;
  48. fastcgi_pass   127.0.0.1:9000;
  49. fastcgi_index  index.php;
  50. fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html$fastcgi_script_name;
  51. # include        fastcgi_params;
  52. }
  53. # deny access to .htaccess files, if Apache's document root
  54. # concurs with nginx's one
  55. #
  56. #location ~ /\.ht {
  57. #    deny  all;
  58. #}
  59. # deny access to .htaccess files, if Apache's document root
  60. # concurs with nginx's one
  61. #
  62. location ~ /(\.svn|\.git|\.ht|\.DS) {
  63. deny all;
  64. internal;
  65. }
  66. }

yii的配置文件

  1. /project/protected/config/main.php
  2. <?php
  3. // uncomment the following to define a path alias
  4. // Yii::setPathOfAlias('local','path/to/local-folder');
  5. // This is the main Web application configuration. Any writable
  6. // CWebApplication properties can be configured here.
  7. return array(
  8. 'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
  9. 'name'=>'My Web Application',
  10. // preloading 'log' component
  11. 'preload'=>array('log'),
  12. // autoloading model and component classes
  13. 'import'=>array(
  14. 'application.models.*',
  15. 'application.components.*',
  16. ),
  17. 'modules'=>array(
  18. // uncomment the following to enable the Gii tool
  19. /*
  20. 'gii'=>array(
  21. 'class'=>'system.gii.GiiModule',
  22. 'password'=>'Enter Your Password Here',
  23. // If removed, Gii defaults to localhost only. Edit carefully to taste.
  24. 'ipFilters'=>array('127.0.0.1','::1'),
  25. ),
  26. */
  27. ),
  28. // application components
  29. 'components'=>array(
  30. 'user'=>array(
  31. // enable cookie-based authentication
  32. 'allowAutoLogin'=>true,
  33. ),
  34. // uncomment the following to enable URLs in path-format
  35. 'urlManager'=>array(
  36. 'urlFormat'=>'path',
  37. 'showScriptName' => false,
  38. 'urlSuffix' => '.html',
  39. 'rules'=>array(
  40. '<controller:\w+>/<id:\d+>'=>'<controller>/view',
  41. '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
  42. '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
  43. ),
  44. ),
  45. // database settings are configured in database.php
  46. 'db'=>require(dirname(__FILE__).'/database.php'),
  47. 'errorHandler'=>array(
  48. // use 'site/error' action to display errors
  49. 'errorAction'=>'site/error',
  50. ),
  51. 'log'=>array(
  52. 'class'=>'CLogRouter',
  53. 'routes'=>array(
  54. array(
  55. 'class'=>'CFileLogRoute',
  56. 'levels'=>'error, warning',
  57. ),
  58. // uncomment the following to show log messages on web pages
  59. /*
  60. array(
  61. 'class'=>'CWebLogRoute',
  62. ),
  63. */
  64. ),
  65. ),
  66. ),
  67. // application-level parameters that can be accessed
  68. // using Yii::app()->params['paramName']
  69. 'params'=>array(
  70. // this is used in contact page
  71. 'adminEmail'=>'webmaster@example.com',
  72. ),
  73. );

重启nginx

    1. [root@localhost protected]# service nginx restart
    2. 停止 nginx:                                               [确定]
    3. 正在启动 nginx:                                           [确定]

yii2 URL重写 nginx的配置的更多相关文章

  1. 【URL重写】IIS7配置URL重写

    URL Rewrite Module   此模块适用于IIS7.7.5.8. 微软在IIS7中添加了URL的重写模块,并且免费使用,可以导入.htaccess规则,但需要安装. 第一步:安装URL2. ...

  2. ASP.NET伪静态 UrlRewrite(Url重写) 实现和配置

    核心提示:大家一定经常在网络上看到很多网站的地址后缀都是用XX.HTML或者XX.ASPX等类似静态文件的标示来操作的吧,那么大家有怀疑过他真的是一个一个的静态生成的文件么,静态文件的生成的优缺有好有 ...

  3. url重写(伪静态)IIS配置图解

    通过IIS创建虚拟目录,新建网站放在该目录下面: IIS配置: 虚拟目录=>点击右键=>选择属性: 点击配置: 点击编辑: 复制两个文本框文本到记事本中=>点击确定: 点击添加=&g ...

  4. centos7 Apache开启URL重写组件并配置.htaccess实现伪静态

    第一.修改httpd.conf文件 A - 在etc/httpd/conf/目录下的httpd.conf 文件,找到: LoadModule rewrite_module modules/mod_re ...

  5. Nginx配置虚拟机,url重写,防盗链

    配置目录: ·     虚拟主机 ·     PHP支持 ·     URL重写 ·     防止盗链 ·     持续更新… 一.虚拟主机 1.创建 文件格式:{域名}.conf 具体如下: $ s ...

  6. (转)nginx下基于ThinkPHP框架的网站url重写

    nginx下基于ThinkPHP框架的网站url重写nginx下的基于thinkphp的应用的url重写,需了解thinkphp的各种url格式参数的处理逻辑以及nginx重写的原理.简单点说,无论哪 ...

  7. nginx的URL重写应用实例

    1,NGINx的URL重写 NGINX 的URL重写模块用的比较多,主要使用的命令有if rewrite set break 2 if命令 语法如下"" 语法:if(conditi ...

  8. asp.net 页面url重写

    不更改情况下,页面路径为index.aspx?id=1,现在输入页面路径index/1时,也能访问到页面,这一过程叫做url重写 ①:在一个类里制定路径重写规则,以下为自定义UrlRewriterFi ...

  9. 转载MSDN 在ASP.NET 中执行 URL 重写

    转载文章原网址 http://msdn.microsoft.com/zh-cn/library/ms972974.aspx 摘要:介绍如何使用 Microsoft ASP.NET 执行动态 URL 重 ...

随机推荐

  1. 关于一些Java基础数据类型的常用方法的应用场景的小思考

    昨天遇到一个问题,按照我的一半解决方法是传一个参数,然后通过参数来控制逻辑处理:但是领导发现String的一个方法也可以完全完成该问题!而我完全没有get到这个点! so,我认识到了自己的知识盲区:基 ...

  2. Yii2中如何访问controller的二级目录下的控制器

    Yii2默认的控制器下只有一层目录放在controller目录下,当开发的需要的时候需要在该目录下面新增一层目录也就是在controller下增加二级目录,比如controller/api/Membe ...

  3. AC日记——Rmq Problem bzoj 3339

    3339 思路: 恶心: 代码: #include <cstdio> #include <cstring> #include <iostream> #include ...

  4. mongodb复制集搭建

    注:mongodb当前版本是3.4.3 1.准备三个虚拟机做服务器 192.168.168.129:27017 192.168.168.130:27017 192.168.168.131:27017 ...

  5. NYOJ 914 Yougth的最大化【二分/最大化平均值模板/01分数规划】

    914-Yougth的最大化 内存限制:64MB 时间限制:1000ms 特判: No 通过数:3 提交数:4 难度:4 题目描述: Yougth现在有n个物品的重量和价值分别是Wi和Vi,你能帮他从 ...

  6. HDFS API 学习:几个常用的API

    1.Hadoop-1.2.1 API 文档:http://hadoop.apache.org/docs/r1.2.1/api/ 2.几个API: create(Path f) :Opens an FS ...

  7. MYSQL从入门到放弃系列:mysql基础语法

    Mysql基本语法 启动MySQL net start mysql 连接与断开服务器 mysql -h 地址 -P 端口 -u 用户名 -p 密码 跳过权限验证登录MySQL mysqld --ski ...

  8. Dijkstra【p4943】密室

    Description 密室被打开了. 哈利与罗恩进入了密室,他们发现密室由n个小室组成,所有小室编号分别为:1,2,...,n.所有小室之间有m条通道,对任意两个不同小室最多只有一条通道连接,而每通 ...

  9. 洛谷——P1722 矩阵 II

    P1722 矩阵 II 题目背景 usqwedf 改编系列题. 题目描述 如果你在百忙之中抽空看题,请自动跳到第六行. 众所周知,在中国古代算筹中,红为正,黑为负…… 给定一个1*(2n)的矩阵(us ...

  10. 洛谷——P1134 阶乘问题

    P1134 阶乘问题 题目描述 也许你早就知道阶乘的含义,N阶乘是由1到N相乘而产生,如: 12! = 1 x 2 x 3 x 4 x 5 x 6 x 7 x 8 x 9 x 10 x 11 x 12 ...