阅读模式:

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

查看:4960  回复: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

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

扫描二维码手机查看

发布评论:


登录:
  表情:
评论话题
推荐阅读:
最简单的Banner轮播左右切换效果代码及实现思路(附带源码)   阅读:34505程序员找工作三要素(必看)   阅读:6518php压缩页面的html代码一行显示   阅读:8699mongodb设置shell开机启动脚本   阅读:11685最简单的Banner轮播左右切换效果代码及实现思路(附带源码)   阅读:34505浅谈javascript的函数节流   阅读:5582session与cookie的区别   阅读:4903centos7.3安装mongodb3.6   阅读:8768mysql数据库性能的基本优化   阅读:5242一键分享到QQ空间、QQ好友、新浪微博、微信代码   阅读:137297Mysql在大型网站的应用架构演变   阅读:5446php打印九九加法表   阅读:12534爱编程,也爱健康   阅读:5235mysql 为什么添加索引可以提高访问速度   阅读:7070php连接redis   阅读:6538ajax+php 实现一个简单的在线聊天室功能(附带源码)   阅读:10924mysql数据一键导出到csv文件   阅读:6759php 使用 smtp.php 类在线发送邮件功能   阅读:6710ajax+php 实现一个简单的在线聊天室功能(附带源码)   阅读:10924php 统计网页打开耗时和脚本运行内存   阅读:7753web项目高并发量网站解决方案   阅读:5421centos 7搭建zabbix3.4   阅读:7602centos 7 安装 samba 服务   阅读:7843php设置cookie为HttpOnly防止XSS攻击   阅读:14226什么是天使轮?什么是A轮融资?B轮融资?   阅读:6153centos 7 安装 nginx-1.11.10   阅读:9597php swoole搭建简单的聊天室   阅读:5855移动端自适应rem原理   阅读:10636csv文件一键导入数据到mysql数据库   阅读:7756简单的DOS攻击之死亡之ping详解   阅读:70174php压缩页面的html代码一行显示   阅读:8699给 centos 7 安装桌面环境   阅读:18076php打印九九乘法表   阅读:12697centos 7 设置 nginx-1.11.10 开机启动   阅读:9027php打印九九乘法表   阅读:12697php打印九九乘法表   阅读:12697面试的时候和你谈理想,是理想or入坑?   阅读:12243crontab+shell脚本实现定时备份mysql数据库   阅读:8703分享:淘宝技术这十年   阅读:5500centos7开启交换内存   阅读:12491简单的DOS攻击之死亡之ping详解   阅读:70174mysql数据一键导出到csv文件   阅读:6759nginx安装redis模块   阅读:7598centos 7 安装 mysql-5.7   阅读:8904centos 7 开启网络   阅读:8332纯干货,程序员面试的超实用技巧   阅读:5104centos 7 设置 nginx-1.11.10 开机启动   阅读:9027解决 nginx 413 request entity too large   阅读:5384php 统计网页打开耗时和脚本运行内存   阅读:7753给php7安装redis扩展库   阅读:9434