Apache如何重写url

1.打开Apache的http.conf,找到LoadModule rewrite_module modules/mod_rewrite.so,如果前面有#则去掉。

2.找到根目录定义的<directory></directory>,添加绿色两行,如下:

<Directory "D:/phpapp/hompage/root">
    Options FollowSymLinks

     AllowOverride All
    Order allow,deny
    Allow from all

</Directory>

AllowOverride All:允许使用.htaccess

为什么用Options FollowSymLinks?

     上网查了一下“在 某些服务器配置中,mod_rewrite要求有followsymlinks,否则会显示500内部服务器错误。

[In some (or all?) server configurations, mod_rewrite requires followsymlinks to be enabled, or it will crater with a 500-Server Error.]

在任何情况下,只要您没有指定FollowSymLinks的选项(即Options FollowSymLinks),或者指定了SymLinksIfOwnerMatch选项,Apache将不得不调用额外的系统函数来检查符号链接。每次针对文件名的请求都将触发一次检查。

如果你没有使用followsymlinks规则而网站访问正常,说明你的服务器配置已经默认调用followsymlinks的重写规则,你无需再为你的htaccess文件定义了。但在有些服务器500 Server Error之后的错误日志中提示需要定义SymLinks使得rewrite重写规则起作用。

If your mod_rewrite code works without the options +followsymlinks directive, that means that your server configuration file has enabled them already, and you won't need that directive in your .htaccess files.

The requirement for enabling followsymlinks is not well-defined. The only way I learned about it was because I got a 500-Server Error the first time I ever enabled mod_rewrite, and the error log entry said something to the effect of, "You must enable SymLinks for this to work."

3.好了之后,到程序的根目录添加.htaccess文件,写入你的rewrite rules,重启apache。

OK~

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值