zoukankan      html  css  js  c++  java
  • Apache开启伪静态

    环境:
    系统 Windows
    Apache 2.2

    加载Rewrite模块:

    在conf目录下httpd.conf中找到

    LoadModule rewrite_module modules/mod_rewrite.so


    这句,去掉前边的注释符号“#”,或添加这句。

    允许在任何目录中使用“.htaccess”文件,将“AllowOverride”改成“All”(默认为“None”):

    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be “All”, “None”, or any combination of the keywords:
    # Options FileInfo AuthConfig Limit
    #
    AllowOverride All

    在Windows系统下不能直接建立“.htaccess”文件,可以在命令行下使用“echo a> .htaccess”建立,然后使用记事本编辑。

    Apache Rewrite模块的简单应用:
    Rewrite的所有判断规则均基于Perl风格的正则表达式,通过以下基础示例能写出符合自己跳转需求的代码。

    1、请求跳转

    目的是如果请求为.jsp文件,则跳转至其它域名访问。

    例如:访问www.clin003.com/a.php跳转至b.clin003.com/b.php网页,访问www.clin003.com/news/index.php跳转至b.clin003.com/news/index.php网页

    注意:不是使用HTML技术中的meta或者javascript方式,因为www.clin003.com/a.php这个文件并不存在,用的是Apache2.2服务器中的Rewrite模块。

    修改 .htaccess或apche的配置文件httpd.conf文件,添加以下内容

    RewriteEngine on
    #开启Rewrite模块
    RewriteRule (.*).php$ http://b.clin003.com/$1.jsp [R=301,L,NC]
    #截获所有.jsp请求,跳转到http://b.clin003.com/加上原来的请求再加上.php。R=301为301跳转,L为rewrite规则到此终止,NC为不区分大小写

    2、域名跳转

    如果请求为old.clin003.com下的所有URL,跳转至b.clin003.com

    RewriteEngine on
    #开启Rewrite模块
    RewriteCond %{REMOTE_HOST} ^old.studenthome.cn$ [NC]
    #针对host为old.clin003.com的主机做处理,^为开始字符,$为结尾字符
    RewriteRule (.*) http://b.clin003.com/$1 [R=301,L,NC]

    3、防盗链

    如果本网站的图片不想让其它网站调用,可以在 .htaccess或者apche的配置文件httpd.conf文件中添加以下内容

    复制代码
    代码
    RewriteEngine on
    #开启Rewrite模块
    RewriteCond %{HTTP_REFERER} !^$
    #如果不是直接输入图片地址
    RewriteCond %{HTTP_REFERER} !img.clin003.com$ [NC]
    #且如果不是img.clin003.com所有子域名调用的
    RewriteCond %{HTTP_REFERER} !img.clin003.com/(.*)$ [NC]
    RewriteCond %{HTTP_REFERER} !zhuaxia.com [NC]
    RewriteCond %{HTTP_REFERER} !google.com [NC]
    RewriteCond %{HTTP_REFERER} !google.cn [NC]
    RewriteCond %{HTTP_REFERER} !baidu.com [NC]
    RewriteCond %{HTTP_REFERER} !feedsky.com [NC]
    RewriteRule (.*).(jpg|jpeg|jpe|gif|bmp|png|wma|mp3|wav|avi|mp4|flv|swf)$ http://clin003.com/err.jpg [R=301,L,NC]
    #截获所有.jpg或.jpeg……请求,跳转到http://clin003.com/err.jpg提示错误的图片,注:该图片不能在原域名下,也不能在该.htaccess文件有效控制的文件夹中
    复制代码



    4、不需要定义.htaccess文件

    在Apache2confhttpd.conf 最后一行添加

    RewriteEngine On
    RewriteRule ^(.*)-htm-(.*)$ $1.php?$2

    重启Apache
    登陆后台开启全伪

     



    GD的Linux主机安装discuz 7.2的注意了

    这个discuz官方给出的伪静态规则
    复制代码
    代码
    # 将 RewriteEngine 模式打开
    RewriteEngine On
    # 修改以下语句中的 /discuz 为你的论坛目录地址,如果程序放在根目录中,请将 /discuz 修改为 /
    RewriteBase /discuz
    # Rewrite 系统规则请勿修改
    RewriteRule ^archiver/((fid|tid)-[w-]+.html)$ archiver/index.php?$1
    RewriteRule ^forum-([0-9]+)-([0-9]+).html$ forumdisplay.php?fid=$1&page=$2
    RewriteRule ^thread-([0-9]+)-([0-9]+)-([0-9]+).html$ viewthread.php?tid=$1&extra=page%3D$3&page=$2
    RewriteRule ^space-(username|uid)-(.+).html$ space.php?$1=$2
    RewriteRule ^tag-(.+).html$ tag.php?name=$1
    复制代码
     

    使用这个规则后,你会发现,点击论坛右下角的网站地图“Archiver”,只能看到板块,不能打开板块下的帖子


    这是修改后的伪静态规则:

    复制代码
    代码
    # 将 RewriteEngine 模式打开
    RewriteEngine On
    # 修改以下语句中的 /discuz 为你的论坛目录地址,如果程序放在根目录中,请将 /discuz 修改为 /
    RewriteBase /
    # Rewrite 系统规则请勿修改
    RewriteRule ^archiver/([a-z0-9-]+.html)$ archiver/index.php?$1
    RewriteRule ^forum-([0-9]+)-([0-9]+).html$ forumdisplay.php?fid=$1&page=$2
    RewriteRule ^thread-([0-9]+)-([0-9]+)-([0-9]+).html$ viewthread.php?tid=$1&extra=page%3D$3&page=$2
    RewriteRule ^space-(username|uid)-(.+).html$ space.php?$1=$2
    RewriteRule ^tag-(.+).html$ tag.php?name=$1
    复制代码
     
    换了这个规则后网站地图“Archiver”则全部正常,特此分享,希望对大家有帮助!


  • 相关阅读:
    Tomcat部署web项目,虚拟目录,上下文(Context),WEB-INF,web.xml,servlet,404
    Android异常:唤醒锁未授权。(Caused by: java.lang.SecurityException: Neither user 10044 nor current process has android.permission.WAKE_LOCK.)
    .hiverc
    Hive安装
    搭建Kafka开发环境
    java实现Kafka的消费者示例
    java实现Kafka生产者示例
    Kafka集群部署
    kafka介绍
    Pig UDF 用户自定义函数
  • 原文地址:https://www.cnblogs.com/shsgl/p/3930715.html
Copyright © 2011-2022 走看看