Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1271196
  • 博文数量: 107
  • 博客积分: 1456
  • 博客等级: 上尉
  • 技术积分: 1868
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-13 15:33
文章分类

全部博文(107)

文章存档

2021年(2)

2016年(8)

2015年(8)

2014年(10)

2013年(20)

2012年(38)

2011年(21)

分类: Python/Ruby

2012-09-24 15:23:19

经常有客户反应Linux服务器不支持伪静态,URL Rewrite等,但实际上都是他们的.htaccess规则没有写好导致的。下面给出一个.htaccess的简单实例,用于排查问题:

 

RewriteEngine on

ErrorDocument 404 /job.php

RewriteRule ^(.*)\.(asp|aspx|asa|asax|dll|jsp|cgi|fcgi|pl)(.*)$ /info.php

Redirect "/index.html" ""

RewriteRule ^download\.html /download.php

 

将以上内容写入一个新文件,命名为.htaccess即可。

 

接下来简单说明一下这几条规则。

 

ErrorDocument 404 /job.php

自定义错误信息。将404错误定义为job.php页面的内容。

 

RewriteRule ^(.*)\.(asp|aspx|asa|asax|dll|jsp|cgi|fcgi|pl)(.*)$ /info.php

URL转发。将.asp\.aspxhttp请求转发至info.php页面。

 

Redirect "/index.html" ""

重定向。将index.html页面重定向至另一个站点:

 

RewriteRule ^download\.html /download.php

URL转发。将对download.html页面的请求转发至download.php页面。

 

其中RewriteRule可用于实现伪静态,如果.htaccess文件里含有这类规则,必须先启用rewrite:RewriteEngine on。

阅读(2453) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~