阅读模式:

windowns主机和linux主机的.htaccess 伪静态规则

查看:2594  回复:0  类型:  来源:php自学网  标签 伪静态

一、Linux主机

    Apache服务器:

        打开apache的配置文件httpd.conf,搜索#LoadModule rewrite_module modules/mod_rewrite.so,开启支持,去掉#,Apache服务。

RewriteEngine On
RewriteBase /
#拒绝直接访问.htaccess文件
<files .htaccess>
order deny,allow
deny from all
</files>
Order Allow,Deny
Allow from all
Deny from 114.215.209.95
#图片防盗链
#RewriteRule .*\.(gif|jpg|png)$ http://zixuephp.net/static/images/logo.png [R,NC,L]
#隐藏服务器数字签名
#ServerSignature Off
#限制最大上传
#LimitRequestBody 10240000
#重定向域名 利于SEO
#RewriteCond %{HTTP_HOST} ^zixuephp.net$ [NC]
#RewriteRule ^(.*)$ http://www.zixuephp.net/$1 [R=301,L]
#错误跳转页面
#ErrorDocument 404 /404.html
#ErrorDocument 403 /404.html
#ErrorDocument 500 /404.html
# proc/self/environ shell拒绝!
#RewriteCond %{QUERY_STRING} proc/self/environ [OR]
# 阻止脚本通过URL传递的base64_encode垃圾信息
#RewriteCond %{QUERY_STRING} base64_encode.*(.*) [OR]
# 阻止在URL含有<script>标记的脚本
#RewriteCond %{QUERY_STRING} (<|%3C).*script.*(>|%3E) [NC,OR]
# 阻止企图通过URL设置PHP的GLOBALS变量的脚本
#RewriteCond %{QUERY_STRING} GLOBALS(=|[|%[0-9A-Z]{0,2}) [OR]
# 阻止企图通过URL设置PHP的_REQUEST变量的脚本
#RewriteCond %{QUERY_STRING} _REQUEST(=|[|%[0-9A-Z]{0,2})
# 把所有被阻止的请求转向到403禁止提示页面!
#RewriteRule ^(.*)$ 404.html [F,L]
#缓存文件,提高网站速度
<FilesMatch “.(flv|gif|jpg|jpeg|png|ico|swf|js|css|pdf|zip|rar)$”>
Header set Cache-Control “max-age=4592000″
</FilesMatch>
# 显式的规定对脚本和其它动态文件禁止使用缓存
#<FilesMatch “.(pl|php|cgi|spl|scgi|fcgi)$”>
#Header unset Cache-Control
#</FilesMatch>
# 压缩 text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
#网站url伪静态
RewriteRule "^index\.html$" index.php
RewriteRule "^iphp\.html$" iphp.php
RewriteRule "^login\.html$" login.php
RewriteRule "^reg\.html$" reg.php
RewriteRule "^post\.html$" post.php
RewriteRule "^article\.html$" article.php
RewriteRule "^article-([0-9]+)\.html$" article.php?aid=$1
RewriteRule "^iphp-([0-9]+)\.html$" iphp.php?mid=$1
RewriteRule "^iphp-([0-9]+)-([0-9]+)\.html$" iphp.php?mid=$1&cid=$2
RewriteRule "^iphp-([0-9]+)-page([0-9]+)\.html$" iphp.php?mid=$1&page=$2
RewriteRule "^iphp-c([0-9]+)-page([0-9]+)\.html$" iphp.php?cid=$1&page=$2
RewriteRule "^search\.html$" search.php
RewriteRule "^tag-([0-9]+)\.html$" tag.php?tid=$1
RewriteRule "^tag-([0-9]+)-page([0-9]+)\.html$" tag.php?mid=$1&tid=$2
RewriteRule "^tool\.html$" tool.php
RewriteRule "^tool-html\.html$" tool-html.php  
RewriteRule "^tool-ip\.html$" tool-ip.php
RewriteRule "^tool-css\.html$" tool-css.php
RewriteRule "^tool-domain-ip\.html$" tool-domain-ip.php
RewriteRule "^tool-md5\.html$" tool-md5.php
RewriteRule "^tool-view-source-code\.html$" tool-view-source-code.php


    nginx服务器:

        nginx服务器伪静态的配置在nginx配置文件(/usr/local/nginx/conf/nginx.conf)中的http模块server虚机中(http{server{  #伪静态 } }),配置代码:

nginx.conf配置文件:

http{
    ...
    
    server{
        #网站伪静态
        location / {
            rewrite "^/index.html$" /index.php last;
            rewrite "^/iphp.html$" /iphp.php last;
            rewrite "^/tag-([0-9]+).html$" /tag.php?tid=$1 last;
            rewrite "^/tag-([0-9]+)-page([0-9]+).html$" /tag.php?tid=$1&page=$2 last;
            rewrite "^/login.html$" /login.php last;
            rewrite "^/post.html$" /post.php last;
            rewrite "^/article.html$" /article.php last;
            rewrite "^/article-([0-9]+).html$" /article.php?aid=$1 last;
            rewrite "^/iphp-([0-9]+).html$" /iphp.php?mid=$1;
            rewrite "^/iphp-([0-9]+)-([0-9]+).html$" /iphp.php?mid=$1&cid=$2 last;
            rewrite "^/iphp-([0-9]+)-page([0-9]+).html$" /iphp.php?mid=$1&page=$2;
            rewrite "^/iphp-c([0-9]+)-page([0-9]+).html$" /iphp.php?cid=$1&page=$2;
            rewrite "^/search.html$" /search.php;
            rewrite "^/tool.html$" /tool.php last;
            rewrite "^/tool-html.html$" /tool-html.php last;
            rewrite "^/tool-ip.html$" /tool-ip.php last;
            rewrite "^/tool-css.html$" /tool-css.php last;
            rewrite "^/tool-domain-ip.html$" /tool-domain-ip.php;
            rewrite "^/tool-view-source-code.html$" /tool-view-source-code.php;
            rewrite "^/tool-md5.html$" /tool-md5.php;
        }
    }
    
    ...
}


二、windows主机

    IIS服务器:

        在网站的根目录,新建web.config文件,配置如下:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="rule1" stopProcessing="true">
                    <match url="^index.html" />
                    <action type="Rewrite" url="index.asp"  />
                </rule>
                <rule name="rule2" stopProcessing="true">
                    <match url="^iphp.html" />
                    <action type="Rewrite" url="iphp.asp"  />
                </rule>   
            </rules>
        </rewrite>
    </system.webServer>     
</configuration>
分享到:
0 0

*有问题之处烦请在评论中指出非常感谢!
不是我想要的内容,继续搜索:

扫描二维码手机查看

发布评论:


登录:
  表情:
评论话题
推荐阅读:
php 获取当前前后年、月、星期、日、时分秒的时间   阅读:3354javascript点击复制内容   阅读:3305程序员找工作三要素(必看)   阅读:3208php 使用 smtp.php 类在线发送邮件功能   阅读:3363最简单的Banner轮播左右切换效果代码及实现思路(附带源码)   阅读:19470程序员找工作三要素(必看)   阅读:3208php冒泡排序法   阅读:5594php翻转字符串   阅读:693最新centos7 搭建LNMP环境(centos7.2+php7+mysql5.7+nginx1.11+redis3.2)   阅读:6873解决 nginx 413 request entity too large   阅读:2533简单的DOS攻击之死亡之ping详解   阅读:23844phpexcel 超简单从数据库一键导出数据到excel教程   阅读:4250linux教程,鸟哥私房菜(pdf全集)   阅读:3203爱编程,也爱健康   阅读:2056关于PHP程序员技术职业生涯规划   阅读:456最简单的Banner轮播左右切换效果代码及实现思路(附带源码)   阅读:19470简单的DOS攻击之死亡之ping详解   阅读:23844php打印九九加法表   阅读:5088centos 7 安装 samba 服务   阅读:3564栈和堆的区别   阅读:2628ajax+php 实现一个简单的在线聊天室功能(附带源码)   阅读:5174linux教程,鸟哥私房菜(pdf全集)   阅读:3203什么是天使轮?什么是A轮融资?B轮融资?   阅读:1993session与cookie的区别   阅读:2420centos 7 添加 redis 3.2.9 开机启动脚本   阅读:5430php翻转字符串   阅读:693移动端自适应rem原理   阅读:6903mysql5.7主从同步配置   阅读:521phpexcel 超简单从数据库一键导出数据到excel教程   阅读:4250nginx安装mysql和json模块   阅读:226linux时间戳有趣的情人节秒1234567890   阅读:2952php打印九九乘法表   阅读:4810栈和堆的区别   阅读:2628mysql数据库性能的基本优化   阅读:2794php打印九九乘法表   阅读:4810php设置cookie为HttpOnly防止XSS攻击   阅读:6384php中地址引用&的真正理解-变量引用、函数引用、对象引用   阅读:3242php+redis实现消息队列   阅读:5082php 读取和设置redis的键值   阅读:4603霍金24岁博士毕业论文在线预览   阅读:2901企业让你去面试,可能不是真的招人   阅读:3505霍金24岁博士毕业论文在线预览   阅读:2901HTTP 1.1 协议详解   阅读:4143php翻转字符串   阅读:693centos7.3安装mongodb3.6   阅读:4302“米粉节”背后的故事——小米网抢购系统开发实践   阅读:2360浅谈javascript的函数节流   阅读:2394centos 7搭建zabbix3.4   阅读:2596php冒泡排序法   阅读:5594网站性能优化-页面静态缓存   阅读:3384