Apache开启Rewrite环境
来源:互联网 发布:mac svn 编辑:程序博客网 时间:2024/06/05 11:53
Apache开启Rewrite环境
环境:
系统 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文件有效控制的文件夹中
关于Windows下Apache应用环境塔建:http://clin003.com/ideas/windows-apache-install-useing-like-php-python-subversion-1330/
关于301重定向的应用:http://clin003.com/search-engine/301-redirect-implementation-784/
用telnet检测网址返回的头部信息状态码:http://clin003.com/servers/detection-using-telnet-to-return-at-the-head-of-the-state-code-information-450/
- Apache开启Rewrite环境
- apache 开启 rewrite 功能
- apache 开启Rewrite
- ubuntu apache开启rewrite
- apache开启rewrite重写
- Apache开启Rewrite模块
- Apache开启Rewrite与Rewrite指令介绍
- apache 开启 rewrite 重写规则 .
- apache 开启 rewrite 重写规则 .
- ubuntu 下开启 apache 的 rewrite 模式
- Ubuntu下apache rewrite模块开启
- 如何开启XAMPP / Apache的rewrite功能
- 开启apache rewrite模块的方法
- 开启apache的url rewrite模块
- ubuntu下Apache开启rewrite模块
- 开启apache的url rewrite模块
- CentOs中Apache开启rewrite模块详解
- apache 开启伪静态 Rewrite及检测
- Javascript跳转页面和打开新窗口等方法
- 用 jQuery 获取 iframe 父页面元素
- 页面中多个小图片元素合成一个大图片之后用CSS调用
- Css背景图合并工具功能增强
- MySQL命令大全经典版
- Apache开启Rewrite环境
- 网站性能测试工具Apache Benchmark的使用说明
- 使Serv-U支持中文目录名中文文件名并解决中文乱码
- Windows下安装最新的Apache+PHP+MySQL指南
- javascript 特效集合
- Mysql 常用到的方法汇总
- 从php网页的代码的编写来防止您的网站被攻击
- 标准SQL注入入侵语句
- 手工入侵网站SQL语句