URL重写工作在.htaccess而不是httpd.conf文件 [英] Apache mod_rewrite works in .htaccess but not httpd.conf

查看:208
本文介绍了URL重写工作在.htaccess而不是httpd.conf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试用mod_rewrite的是第一次(我是一个网络新手,但努力学习)。我试图让 bob.html 重定向到 alice.html (读:网址保持不变,网页内容的 alice.html )。这两个文件都在 /无功/网络/ 。我运行Ubuntu10.10瓦特/阿帕奇2.2.16。

I'm experimenting with mod_rewrite for the first time (I'm a web newbie, but trying to learn). I'm trying to get bob.html to redirect to alice.html (read: URL stays the same, page content is alice.html). Both files are in /var/www/. I'm running Ubuntu 10.10 w/Apache 2.2.16.

下面是在什么样的工作的.htaccess 放在 /无功/网络/ 目录下的文件:

Here's what works in the .htaccess file placed in the /var/www/ directory:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^bob.html$ alice.html
</IfModule>

此行​​为与预期,但是当移动到httpd.conf文件(刚学的最佳实践瓦特/性能等等)这是行不通的。我读的地方,在使用mod_rewrite时的httpd.conf 文件,导致斜线是必需的,所以我的的httpd.conf 文件看起来像:

This behaves as expected, but it does not work when moved to the httpd.conf file (just learning best practices w/performance and such). I read somewhere that when using mod_rewrite in httpd.conf file, leading slashes are required, so my httpd.conf file looks like:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^/bob.html$ /alice.html
</IfModule>

我也读到的的/ etc / apache2的/站点启用/ 000默认需要有的AllowOverride 设置为所有

<Directory /var/www> 
...
AllowOverride All
...
</Directory>

我的认为的,这只是与使用的.htaccess ,但我不知道,所以我刚刚离开它

I think that's just for use with .htaccess but I wasn't sure so I just left it in.

随着这些配置设置,重定向不起作用。我测试过,以确保自己正在读取的文件(有人建议的httpd.conf 不再使用和 apache2.conf 是用来代替),通过插入错误的$ C $℃。我已经看到了在其他几个问题/答案,但我仍然不能看着办吧。

With all of these configuration settings, the redirection does not work. I've tested to make sure the file itself is being read (someone suggested httpd.conf isn't used anymore and apache2.conf is used instead) by inserting erroneous code. I've taken a look at a couple other questions/answers but I still cant figure it out.

修改的:应当指出的是,我使用的 /etc/init.d/apache2重启每次更改为的httpd.conf 重新启动Apache和(希望)重新载入配置。

Edit: It should be noted that I'm using /etc/init.d/apache2 restart after each change to httpd.conf to restart Apache and (hopefully) reload the configuration.

推荐答案

尝试包裹在httpd.conf文件中的规则集与&lt;位置/&GT;&LT; /地点&gt;标签。在似乎改变行为,使其更类似于.htaccess文件。

Try wrapping the rewriterules in your httpd.conf file in <Location /></Location> tags. The seems to alter the behavior making it more similar to the .htaccess file.

这篇关于URL重写工作在.htaccess而不是httpd.conf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆