Apache mod_rewrite模块配置

本文介绍了如何配置Apache的mod_rewrite模块,包括启用模块、设置Directory指令以允许URL重写,并强调了Options FollowSymLinks的重要性,以及在遇到权限错误时如何解决。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

配置apache的重写模块,保证以下几点

1. 启用mod_rewrite模块
    在conf目录的httpd.conf文件中找到
    LoadModule rewrite_module modules/mod_rewrite.so
   将这一行前面的#去掉。


2. 在要支持url rewirte的目录启用 Options FollowSymLinks和AllowOverride All

   <Directory "/home/ghicd/htdocs">
        Options Indexes FollowSymLinks
        AllowOverride All
       Order allow,deny
       Allow from all
  </Directory>
这样通过http://localhost:8080/访问时,/htdocs/和其下面的子目录都将支持url rewrite。


网上的很多文章并没有提到要使用 Options FollowSymLinks,因为在httpd.conf中有

<Directory />

    Options FollowSymLinks

    AllowOverride None
    Order deny,allow
    Deny from all
    Satisfy all
</Directory>
这样如果你的网站配置成通过http://localhost:8080/来访问,就不会注意到Options FollowSymLinks的影响,只需要将AllowOverride None改为AllowOverride All即可。

而我习惯于在本机配置成http://localhost:8080/php/,忘了加Options Indexes FollowSymLinks就成功不了,会显示
Forbidden  You don't have permission to access /php/f2blog/ on this server.
这样的错误。后来还是在apache文档中找到了原因
Note: To enable the rewriting engine for per-directory configuration files you need to set ``RewriteEngine On'' in these files and ``Options FollowSymLinks'' must be enabled. If your administrator has disabled override of FollowSymLinks for a user's directory, then you cannot use the rewriting engine. This restriction is needed for security reasons.
实际上mod_rewrite是针对目录的,因此并不需要将httpd.conf中的所有AllowOverride None改为AllowOverride All,Options也一样。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值