阅读模式:

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

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

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

扫描二维码手机查看

发布评论:


登录:
  表情:
评论话题
推荐阅读:
mysql5.7主从同步配置   阅读:6450mysql共享锁和排他锁详解   阅读:7731Nginx 配置文件详解   阅读:5119crontab+shell脚本实现定时备份mysql数据库   阅读:8014linux rarcrack破解rar、zip和7z压缩包简单密码的工具   阅读:18159面试的时候回去等通知,等电话的真实意思   阅读:24635centos 7 添加 redis 3.2.9 开机启动脚本   阅读:9830爱编程,也爱健康   阅读:4581mysql数据库性能的基本优化   阅读:4716shell脚本批量删除几天前的文件   阅读:10595十张GIF让你弄懂递归等概念   阅读:6405phpexcel 超简单从excel表格一键导入数据到数据库教程   阅读:12587把php session 会话保存到redis   阅读:7618什么是天使轮?什么是A轮融资?B轮融资?   阅读:5319php 获取当前前后年、月、星期、日、时分秒的时间   阅读:7066小米手机端商城rem适配原理   阅读:6990php中地址引用&的真正理解-变量引用、函数引用、对象引用   阅读:6062小米手机端商城rem适配原理   阅读:6990linux rarcrack破解rar、zip和7z压缩包简单密码的工具   阅读:18159给网站添加一键新浪微博登录的功能   阅读:6800给 centos 7 安装桌面环境   阅读:17274centos 7 添加 redis 3.2.9 开机启动脚本   阅读:9830给网站添加一键qq登录的功能   阅读:7864crontab+shell脚本实现定时备份mysql数据库   阅读:8014网站局部小图片优化-base64编码图片   阅读:18970把php session 会话保存到redis   阅读:7618浅谈javascript的函数节流   阅读:4946session与cookie的区别   阅读:4389最简单的Banner轮播淡入淡出效果代码及实现思路(附带源码)   阅读:13735Mysql在大型网站的应用架构演变   阅读:4947centos7开启交换内存   阅读:11375面试的时候和你谈理想,是理想or入坑?   阅读:10978centos7.3安装mongodb3.6   阅读:7923php 统计网页打开耗时和脚本运行内存   阅读:7092关于PHP程序员技术职业生涯规划   阅读:3140给网站添加一键新浪微博登录的功能   阅读:6800centos 7 设置 nginx-1.11.10 开机启动   阅读:8279网站局部小图片优化-base64编码图片   阅读:18970mysql中文分词全文搜索索引讯搜的安装   阅读:7256HTTP 1.1 协议详解   阅读:12926用php从1加到100的值   阅读:9079移动端自适应rem原理   阅读:9963linux php7编译安装mongodb扩展   阅读:9279一键分享到QQ空间、QQ好友、新浪微博、微信代码   阅读:132307面试的时候回去等通知,等电话的真实意思   阅读:24635给php7安装redis扩展库   阅读:8580网站局部小图片优化-base64编码图片   阅读:18970人性漫画:打工与创业的残酷区别   阅读:5176把php session 会话保存到redis   阅读:7618centos 7 安装 php-7.1.3   阅读:20838