URL重写工作在.htaccess而不是httpd.conf文件

编程入门 行业动态 更新时间:2024-10-19 15:37:59
本文介绍了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文件

本文发布于:2023-11-01 01:40:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1547876.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重写   而不是   文件   工作   URL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!