`
lovexuwenhao
  • 浏览: 200322 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

Apache rewrite例子集合

阅读更多
在 httpd 中将一个域名转发到另一个域名
虚拟主机世界近期更换了域名,新域名为 www.wbhw.com, 更加简短好记。这时需要将原来的域名 webhosting-world.com, 以及论坛所在地址 webhosting-world.com/forums/ 定向到新的域名,以便用户可以找到,并且使原来的论坛 URL 继续有效而不出现 404 未找到,比如原来的 http://www. webhosting-world.com/forums/-f60.html, 让它在新的域名下继续有效,点击后转发到 http://bbs.wbhw.com/-f60.html, 这就需要用 apache 的 Mod_rewrite 功能来实现。

在< virtualhost> 中添加下面的重定向规则:

RewriteEngine On
# Redirect webhosting-world.com/forums to bbs.wbhw.com
RewriteCond %{REQUEST_URI} ^/forums/
RewriteRule /forums/(.*) http://bbs.wbhw.com/$1 [R=permanent,L]

# Redirect webhosting-world.com to wbhw.com
RewriteCond %{REQUEST_URI} !^/forums/
RewriteRule /(.*) http://www.wbhw.com/$1 [R=permanent,L]

添加了上面的规则以后, 里的全部内容如下:
< virtualhost *:80>
ServerAlias webhosting-world.com
ServerAdmin admin@webhosting-world.com
DocumentRoot /path/to/webhosting-world/root
ServerName www.webhosting-world.com

RewriteEngine On
# Redirect webhosting-world.com/forums to bbs.wbhw.com
RewriteCond %{REQUEST_URI} ^/forums/
RewriteRule /forums/(.*) http://bbs.wbhw.com/$1 [R=permanent,L]

# Redirect webhosting-world.com to wbhw.com
RewriteCond %{REQUEST_URI} !^/forums/
RewriteRule /(.*) http://www.wbhw.com/$1 [R=permanent,L]
< /virtualhost>




URL重定向例子一:
1.http://www.zzz.com/xxx.php-> http://www.zzz.com/xxx/
2.http://yyy.zzz.com-> http://www.zzz.com/user.php?username=yyy 的功能

RewriteEngine   On
RewriteCond   %{HTTP_HOST}   ^www.zzz.com
RewriteCond   %{REQUEST_URI}   !^user\.php$
RewriteCond   %{REQUEST_URI}   \.php$
RewriteRule   (.*)\.php$   http://www.zzz.com/$1/   [R]

RewriteCond   %{HTTP_HOST}   !^www.zzz.com
RewriteRule   ^(.+)   %{HTTP_HOST}   [C]
RewriteRule   ^([^\.]+)\.zzz\.com   http://www.zzz.com/user.php?username=$1


例子二:
/type.php?typeid=*  --> /type*.html
/type.php?typeid=*&page=*  --> /type*page*.html

RewriteRule ^/type([0-9]+).html$ /type.php?typeid=$1   [PT]
RewriteRule ^/type([0-9]+)page([0-9]+).html$ /type.php?typeid=$1&page=$2   [PT]
分享到:
评论

相关推荐

    Apache Rewrite Module 的重定向问题

    ### Apache Rewrite Module 重定向问题解析 #### 一、Apache Rewrite Module 概述 Apache的Rewrite Module(重写模块)是Apache服务器中一个非常强大的工具,主要用于URL重写及重定向功能。它通过一系列规则对请求...

    apache_rewrite语法

    apache_rewrite语法的详细解析,实现php的URL重写。

    Apache的ReWrite的应用

    Apache的Rewrite模块是HTTP服务器Apache中的一个强大功能,它允许服务器根据预定义的规则重写URL,这对于网站优化、动态URL转换为静态URL、隐藏真实路径、实现URL短化等场景非常有用。Rewrite模块基于Perl兼容正则...

    UrlRewrite例子

    首先,UrlRewrite是Tuckey开源组织提供的一款过滤器,它基于Apache的开源项目 mod_rewrite 的思想,实现了在Servlet容器(如Tomcat)中的URL重写功能。通过在web.xml中配置UrlRewriteFilter,我们可以定义一系列规则...

    Apache Rewrite url重定向功能的简单配置

    平时帮助我们实现拟静态,拟目录,域名跳转,防止盗链等 2.Apache Rewrite的配置 Apache下的Rewrite配置主要有两种,一种是针对整个apache服务器的配置,此种配置的Rewrite规则是直接在httpd.conf下书写。...

    解析 .htaccess 文件 apache rewrite

    模块`mod_rewrite`是Apache的一个核心模块,它提供了URL重写和URL路由的能力,这对于创建SEO友好的伪静态URL、实现URL短链、隐藏真实路径等场景非常有用。在`.htaccess`文件中启用`mod_rewrite`模块,你需要开启...

    apache rewrite rule

    Apache Rewrite Rule是Apache服务器中的一种功能,用于URL重写,它是Apache HTTP服务器的mod_rewrite模块的核心功能。这个功能使得Web服务器能够根据预定义的规则,将用户请求的URL转换为另一种形式,通常是为了优化...

    Apache URL Rewrite功能配置

    ### Apache URL Rewrite功能配置知识点详解 #### 一、Apache URL Rewrite简介 Apache URL Rewrite功能是Apache Web服务器的一个强大工具,它允许用户通过一系列规则来改变客户端请求的URL,从而实现URL重写、...

    Apache rewrite重写规则的常见应用

    为了让客户不会因此受到任何影响,最好的方法就是使用Apache Rewrite Rule(重写规则)。  二、重写规则的作用范围  —- 1.使用在Apache主配置文件httpd.conf中。  —- 2.使用在httpd.conf里定义的配置中。 ...

    linux_apache_rewrite编译配置.pdf

    《Linux Apache Rewrite编译配置详解》 Apache Rewrite模块是Apache HTTP服务器中的一个重要组件,主要用于URL重写和路由重定向。这个模块使得我们能够基于正则表达式对请求的URL进行动态转换,从而实现诸如隐藏...

    Apache rewrite的重写相关的参数说明

    Apache的mod_rewrite模块是Web服务器中的一个强大工具,它允许我们通过定义规则来重写URL,从而实现诸如URL美化、隐藏真实路径、实现重定向等多种功能。以下是对Apache rewrite重写参数及其用法的详细说明: 1. **R...

    apache rewrite_module模块使用教程

    本文将详细介绍如何使用`mod_rewrite`模块,并提供实际应用的例子。 #### 二、`mod_rewrite`模块简介 `mod_rewrite`是Apache服务器中的一个可选模块,用于对HTTP请求进行URL转换。该模块可以通过一系列预定义的...

    Apache Mod Rewrite 手册

    珍藏的Apache mod write 帮助手册,希望对大家有用

    apache 开启重定向 rewrite的实现方法

    apache 开启重定向 rewrite的实现方法 1.开启重定向模块 $ ln -s /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enable/rewrite.load 2.修改配置文件(某些php框架需要) $ vim /etc/apache2/...

    url rewrite的例子

    一种rewrite称为一个规则,上面的例子就是3个规则。rewrite技术可以在代理服务器实现,或者可以在tomcat之类的java web服务器实现。 Apache HTTP Server 2.x 和 mod_proxy提供了不错的Rewrite处理方法。so如果使用...

    让Apache支持Rewrite静态页面重写的方法

    Apache 1.x 的用户请检查 conf/httpd.conf 中是否存在如下两段代码: LoadModule rewrite_module libexec/mod_rewrite.so AddModule mod_rewrite.c Apache 2.x 的用户请检查 conf/httpd.conf 中是否存在如下一段...

    Apache的Mode Rewrite模块和.htaccess文件配合.docx

    Apache的Mode Rewrite模块和.htaccess文件配合 Apache的Mode Rewrite模块和.htaccess文件配合是Apache服务器中两个非常重要的组件,特别是在网站开发和部署中。下面我们将详细介绍这两个组件的概念、配置方法和应用...

    apache rewrite规则实现白名单

    Apache Rewrite 规则是Apache HTTP服务器中的一个模块mod_rewrite的功能,用于URL重写和路由重定向。这个功能在网站优化、动态URL转换为静态URL、实现URL隐藏、以及访问控制等方面非常有用。在这个特定的需求中,...

    如何在Ubuntu下启动Apache的Rewrite功能.docx

    启用Apache的Rewrite功能是一项重要的配置工作,它允许你通过修改URL(重写规则)来进行URL美化、隐藏真实路径或者实现其他高级路由逻辑。下面将详细介绍如何在Ubuntu下启动Apache的Rewrite功能。 首先,Apache的...

Global site tag (gtag.js) - Google Analytics