ITeye博客

apache 重写配置问题

jackyoo8 · 2008-08-20 18:36 · php · Markdown

由于采用.htaccess方式重写 网站目录设置 allowoverride none 导致网页无法打开 none 改成 all 一切正常

我们先放下面的部分到httpd.conf options Indexes followsymlinks allowoverride all

相关信息:

一、httpd.conf的实现方法

我们放下面的部分到/opt/apache2/conf/httpd.conf

options Indexes followsymlinks allowoverride all rewriteengine on rewritebase / rewriterule ^(.*)$ index.html.en

注: A. rewriteengine on 为重写引擎开关,如果设为off,则任何重写规则定义将不被应 用,该开关的另一好处就是如果为了临时拿掉重写规则,则改为off再重启动Apache即 可,不必将下面一条条的重写规则注释掉。 B.rewritebase / 的作用是如果在下面的rewriterule定义中被重写后的部分(此处为文件名index.html.en) a.前面没有/,则是相对目录,相对于这个rewritebase后面的定义也就是/usr/local/apache/htdocs/index.html.en,
b.如果此处没有rewritebase /这 一项,则被重写成 http://192.168.xxx.xxx/usr/local/apache/htdocs/manual/index.html.en ,显然是不正确的。

不过这里我们也可以不用rewritebase / , 而改为 rewriteengine on rewriterule ^(.)$ /index.html.en
或者 rewriteengine on rewriterule ^(.
)$ http://192.168.1.56/index.html.en

二、.htaccess的实现方法

我们先放下面的部分到httpd.conf

options Indexes followsymlinks allowoverride all

然后放下面的部分到/usr/local/apache/htdocs/manual/.htaccess中 rewriteengine on rewritebase / rewriterule ^(.*)$ index.html.en

注:对文件.htaccess所作的任何改动不需要重启动Apache.

问:要是把这个manual目录重定向到用户jephe的自己的主目录呢? 用下面的.htaccess方案。 rewriteengine on rewritebase /~jephe/ rewriterule ^(.*)$ $1

则对manual目录下任何文件的请求被重定向到~jephe目录下相同文件的请求。

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。