php 伪静态

1Apache 实现伪静态

第一步: 打开apache的httpd_conf文件,打开mod_rewrite模块

 LoadModule rewrite_module modules/mod_rewrite.so

第二步: 把网站的 把 AllowOverride None 换成 AllowOverride All

  <Directory "D:\phpStudy\WWW\96\96weixin.tool">
	  Options FollowSymLinks ExecCGI
	  AllowOverride All
	  Order allow,deny
	  Allow from all
	  Require all granted
</Directory>

第三步: 配置.htaccess 文件

		 <IfModule mod_rewrite.c>
	  	  Options +FollowSymlinks -Multiviews
		  RewriteEngine on
		  RewriteCond %{REQUEST_FILENAME} !-d
		  RewriteCond %{REQUEST_FILENAME} !-f

		 # LGD 伪静态规则
	 	  RewriteRule ^admin index.php?/$1 [QSA,PT,L]
		  RewriteRule ^about/([a-z]*)/? index.php?s=/index/abouts/$1
		  RewriteRule ^([A-Za-z0-9]+)(/?)$ index.php?s=/index/category/index&classpath=$1
		  RewriteRule ^([A-Za-z0-9]*)/([0-9]*).html$ index.php?s=/index/article/detail&id=$2
		</IfModule>

2 Nginx 配置伪静态

 server {
    listen       80;
    server_name tool.96weixin.com;
    root   /wwwroot/website/tool/public;
    rewrite  ^/admin/(.*)$  /index.php?s=/admin/$1  last;
    rewrite ^/([A-Za-z0-9]+)(/?)$ /index.php?s=/index/category/index&classpath=$1;
    rewrite ^/([A-Za-z0-9]*)/([0-9]*).html$ /index.php?s=/index/article/detail&id=$2;
    rewrite ^/([A-Za-z0-9]*)/(.*)/([0-9]*).html$ /index.php?s=/index/article/detail&id=$3;
    rewrite ^/([A-Za-z0-9]*)/index_?([0-9]*).html$ /index.php?s=/index/category/index&classpath=$1&page=$2;
    location / {
        index  index.html index.htm index.php;
        #autoindex  on;
    }
    location ~ [^/]\.php(/|$) {
               try_files $uri =404;
               fastcgi_pass  127.0.0.1:9000;
               fastcgi_index index.php;
               include fastcgi.conf;
       }

}

注意: 同一条规则在 Apache 下 与 Nginx 下写法有差距
比如: Apache 下 : ^([A-Za-z0-9]+)(/?)$ index.php?s=/index/category/index&classpath=$1
而在nginx 下:^/([A-Za-z0-9]+)(/?)$ /index.php?s=/index/category/index&classpath=$1; ( 多两个斜杠 )

转载于:https://my.oschina.net/u/2930993/blog/1863023

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值