阅读模式:

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

查看:4699  回复: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>
分享到:
1 0

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

扫描二维码手机查看

发布评论:


登录:
  表情:
评论话题
推荐阅读:
php删除一个文件夹内的所有文件夹和文件   阅读:5377linux rarcrack破解rar、zip和7z压缩包简单密码的工具   阅读:18683centos7开启交换内存   阅读:11711linux top命令详解   阅读:10220移动端自适应rem原理   阅读:10181比phpexcel还要简单的excel CSV 一键导入数据到数据库   阅读:5801php生成二维码   阅读:7440php打印三角形   阅读:11716shell脚本破解十位数内的所有纯数字rar加密压缩包脚本   阅读:9755crontab+shell脚本实现定时备份mysql数据库   阅读:8254centos 7搭建zabbix3.4   阅读:7128mysql数据一键导出到csv文件   阅读:6225centos 7.2 添加php7 的 php-fpm 开机启动   阅读:25776php+redis实现消息队列   阅读:15909网站性能优化-页面静态缓存   阅读:5905什么是天使轮?什么是A轮融资?B轮融资?   阅读:5577php生成二维码   阅读:7440面试的时候和你谈理想,是理想or入坑?   阅读:11434centos 7 安装 nginx-1.11.10   阅读:9116给网站添加一键新浪微博登录的功能   阅读:6968shell发送邮件脚本   阅读:9152centos7.3安装mongodb3.6   阅读:8206php打印九九乘法表   阅读:11589php 读取和设置redis的键值   阅读:7812给网站添加一键新浪微博登录的功能   阅读:6968TCP的三次握手(建立连接)和四次挥手(关闭连接)   阅读:4291网站局部小图片优化-base64编码图片   阅读:20256centos 7 安装 mysql-5.7   阅读:7761浅谈javascript的函数节流   阅读:5155centos7.3安装mongodb3.6   阅读:8206html5 离线缓存的使用   阅读:4746最简单的Banner轮播淡入淡出效果代码及实现思路(附带源码)   阅读:14107mongodb设置shell开机启动脚本   阅读:11089mysql共享锁和排他锁详解   阅读:7984phpexcel 超简单从excel表格一键导入数据到数据库教程   阅读:12850网站局部小图片优化-base64编码图片   阅读:20256人性漫画:打工与创业的残酷区别   阅读:5400PHP 鸟哥:我也曾经是“不适合”编程的人   阅读:15572centos 7 安装 redis 3.2.9   阅读:7115nginx编译安装后对nginx进行平滑升级   阅读:7250csv文件一键导入数据到mysql数据库   阅读:7274mysql中文分词全文搜索索引讯搜的安装   阅读:7504移动端js触摸touch详解(附带案例源码)   阅读:17678html5 离线缓存的使用   阅读:4746面试的时候回去等通知,等电话的真实意思   阅读:25142HTTP 1.1 协议详解   阅读:13848给 centos 7 安装桌面环境   阅读:17512面试的时候和你谈理想,是理想or入坑?   阅读:11434简单的DOS攻击之死亡之ping详解   阅读:63555浅谈javascript的函数节流   阅读:5155