apache mod_rewrite 不适用于 .htaccess 文件 [英] apache mod_rewrite not working with .htaccess file

查看:13
本文介绍了apache mod_rewrite 不适用于 .htaccess 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我在使用 aws 或其他方面遇到了一些问题,以至于我似乎无法让 mod_rewrite 工作.

OK, I've been having some issues with aws or something, such that I cannot seem to get mod_rewrite to work.

仅出于测试目的,我做了以下操作:

Just for testing purposes I've done the following:

1 使用 aws 控制台从向导部署新的 ami 64 位实例

1 used aws console to deploy fresh ami 64 bit instance from wizard

2 yum 安装 apache

2 yum installed apache

3 编辑/etc/httpd/conf/httpd.conf:这样

3 edited /etc/httpd/conf/httpd.conf: so that

<Directory />
    Options FollowSymLinks
    AllowOverride None
</Directory>

看起来像

<Directory />
    Options FollowSymLinks
    AllowOverride All
</Directory>

4 确保

LoadModule rewrite_module modules/mod_rewrite.so

在文件中且未注释.

5 重启 apache:

5 restarted apache:

 sudo /sbin/service httpd restart

6 创建了两个新文件:

6 created two new files:

/var/www/html/test1.html

包含:

this is test1!

/var/www/html/test2.html

包含:

this is test2!

7 创建的文件:

/var/www/html/.htaccess

包含(总共):

RewriteEngine on
RewriteRule ^test1.html$ test2.html [L]

8 去了:

http://[my aws server]/test1.html

我收到这是 test1!"

Am getting "this is test1!"

我在这里做错了,但对于我的生活,我不知道是什么.非常感谢任何帮助...

I am doing something wrong here, but for the life of me I have no idea what. Any help is greatly appreciated...

我在我的 .htaccess 文件的开头添加了无意义的字符/数字,并重新启动了 apache(不是 100% 确定需要,但是嘿...),什么也没发生.换句话说,我预计访问 url [aws server]/test1.html 会导致某种错误,但事实并非如此.我怀疑 apache 甚至没有读取 .htaccess 文件.

I added nonsense chars/numbers to the beginning of my .htaccess file, and restarted apache (not 100% sure that is needed, but what the hey...), and nothing happened. In other words, I expected that going to the url [aws server]/test1.html would result in some kind of error, but it did not. I suspect apache is not even reading the .htaccess file.

我在 httpd.conf 文件中添加了以下内容:

I added the following to my httpd.conf file:

RewriteLog "/tmp/rewrite.log"
RewriteLogLevel 9

该文件是在我重新启动 apache 时创建的,但是当我转到我设置的任一页面时,那里没有任何内容.我没有在这里做一些非常非常基本的事情,但我不确定是什么......

The file is created when I restart apache, but nothing ever goes in there when I go to either page I've set up. I'm failing to do something very, very basic here, but I'm not sure what...

推荐答案

不确定这是否是您的问题的原因,但您不应该弄乱

Not sure if this is the cause of your problems, but you shouldn't mess with the

<Directory />
    Options FollowSymLinks
    AllowOverride None
</Directory>

行,它应该是这样的:

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Deny from all
</Directory>

您应该将文档根目录添加为不同的容器:

<Directory /var/www/html/>
    Options FollowSymLinks
    AllowOverride All
    Allow from all
</Directory>

这篇关于apache mod_rewrite 不适用于 .htaccess 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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