php 伪静态

原创
2018/07/25 16:59
阅读数 122

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; ( 多两个斜杠 )
展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部