apacherewrite

 1. 检查apache的版本

  Apache 1.x 的加载模块代码

 LoadModule rewrite_module libexec/mod_rewrite.so
  AddModule mod_rewrite.c
  Apache 2.x 的加载模块代码

  LoadModule rewrite_module modules/mod_rewrite.so

 

Apache配置:

支持 httpd.conf  配置和目录  .htaccess 配置
启用 rewrite
# LoadModule rewrite_module modules/mod_rewrite.so
去除前面的  #
LoadModule rewrite_module modules/mod_rewrite.so
启用 .htaccess
AllowOverride None     修改为:   AllowOverride All
------------------------------------------------------------------------------
让apache服务器支持.htaccess
如何让自己的本地APACHE服务器支持”.htaccess”呢?其实只要简单修改一下apache的httpd.conf设置就可以让APACHE支 持.htaccess了。打开httpd.conf文件用文本编辑器打开后,查找
<Directory />
Options FollowSymLinks
AllowOverride  None
</Directory>
改为
<Directory />
Options FollowSymLinks
AllowOverride  All
</Directory>
就可以了。


RewriteEngine On
RewriteBase /

伪静态
RewriteRule ^(article)-([0-9]+)/.htm$  $1.php/?id=$2
根据IP阻止用户访问
order allow,deny
deny from 127.0.0.1
allow from all

Redirects 转向
Redirect /article.php http://www.baidu.com

防止.htaccess文件被查看
order allow,deny
deny from all 

制作错误提醒页面
ErrorDocument 404 http://www.baidu.com


添加 MIME 类型
AddType application/x-shockwave-flash swf
Tips: 设置类型为 application/octet-stream 将提示下载

改变缺省的首页文件 
DirectoryIndex aa.html index.html index.pl default.htm

防止目录列表时显示
IndexIgnore *
 
2.一 个简单的例子
将输入 folio.test.com 的域名时跳转到profile.test.com

listen 8080
NameVirtualHost 10.122.89.106:8080 
ServerAdmin webmaster@colorme.com.cn
DocumentRoot "/usr/local/www/apache22/data1/"
ServerName profile.test.com
RewriteEngine on 
RewriteCond %{HTTP_HOST} ^folio.test.com [NC]
RewriteRule ^/(.*) http://profile.test.com/ [L]

更多的例子请参考:

http://www.cnblogs.com/huanghai/archive/2010/09/27/1836395.html
http://www.path8.net/tn/archives/1361

 



 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值