X
活动推荐

阿里云高性能云主机2折293元/年

企业级性能云服务器限时2折起
新用户5折爆款服务器会场
查看详情 293元/年
阅读模式:

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

查看:3525  回复: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+redis实现消息队列   阅读:10494centos 7 安装 php-7.1.3   阅读:15809centos 7搭建zabbix3.4   阅读:4589centos 7 设置 nginx-1.11.10 开机启动   阅读:6750小米手机端商城rem适配原理   阅读:5792phpexcel 超简单从excel表格一键导入数据到数据库教程   阅读:10379centos 7 修改系统屏幕分辨率   阅读:35677小米手机端商城rem适配原理   阅读:5792企业让你去面试,可能不是真的招人   阅读:4884给网站添加一键新浪微博登录的功能   阅读:5536简单的DOS攻击之死亡之ping详解   阅读:36209centos 7 开启网络   阅读:4869crontab+shell脚本实现定时备份mysql数据库   阅读:5917程序员找工作三要素(必看)   阅读:4641小米手机端商城rem适配原理   阅读:5792php设置cookie为HttpOnly防止XSS攻击   阅读:9983php显示刚刚、几分钟前、几小时前、几天前的函数   阅读:6339php+redis实现消息队列   阅读:10494浅谈javascript的函数节流   阅读:3725phpexcel 超简单从excel表格一键导入数据到数据库教程   阅读:10379网站性能优化-页面静态缓存   阅读:4594简单的DOS攻击之死亡之ping详解   阅读:36209程序员找工作三要素(必看)   阅读:4641web项目高并发量网站解决方案   阅读:3660mysql的四种索引类型   阅读:16639用php从1加到100的值   阅读:6993linux时间戳有趣的情人节秒1234567890   阅读:4424nginx安装mysql和json模块   阅读:2811centos 7 设置 nginx-1.11.10 开机启动   阅读:6750php中地址引用&的真正理解-变量引用、函数引用、对象引用   阅读:4533mysql共享锁和排他锁详解   阅读:5797mysql5.7主从同步中binlog同步模式详解   阅读:3993给网站添加一键新浪微博登录的功能   阅读:5536给网站添加一键新浪微博登录的功能   阅读:5536linux命令中执行php脚本   阅读:5581php 获取当前前后年、月、星期、日、时分秒的时间   阅读:5149shell脚本破解十位数内的所有纯数字rar加密压缩包脚本   阅读:7120PHP 鸟哥:我也曾经是“不适合”编程的人   阅读:10694shell发送邮件脚本   阅读:4682centos 7 设置 nginx-1.11.10 开机启动   阅读:6750linux教程,鸟哥私房菜(pdf全集)   阅读:7131TCP的三次握手(建立连接)和四次挥手(关闭连接)   阅读:2030php生成二维码   阅读:4470mysql5.7开启sql日志的配置   阅读:7021centos 7 忘记root密码   阅读:3839给 centos 7 安装桌面环境   阅读:15108最简单的Banner轮播淡入淡出效果代码及实现思路(附带源码)   阅读:11253php生成二维码   阅读:4470php生成二维码   阅读:4470企业让你去面试,可能不是真的招人   阅读:4884