第一步: 打開apache的httpd_conf文件,打開mod_rewrite模塊php
LoadModule rewrite_module modules/mod_rewrite.so
第二步: 把網站的 把 AllowOverride None 換成 AllowOverride Allhtml
<Directory "D:\phpStudy\WWW\96\96weixin.tool"> Options FollowSymLinks ExecCGI AllowOverride All Order allow,deny Allow from all Require all granted </Directory>
第三步: 配置.htaccess 文件nginx
<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>
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; }
}web
注意: 同一條規則在 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; ( 多兩個斜槓 )