linux - apache mod_rewrite 不适用于 .htaccess 文件

标签 linux .htaccess mod-rewrite amazon-web-services

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

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

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

2 yum 安装apache

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

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

看起来像

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

4 确保

LoadModule rewrite_module modules/mod_rewrite.so

在文件中且未注释。

5 重启apache:

 sudo /sbin/service httpd restart

6 创建了两个新文件:

/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!”

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

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

编辑:我将以下内容添加到我的 httpd.conf 文件中:

RewriteLog "/tmp/rewrite.log"
RewriteLogLevel 9

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

最佳答案

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

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

行,它应该是这样的:

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

你应该 add the directory of your document root as a different container :

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

关于linux - apache mod_rewrite 不适用于 .htaccess 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17868819/

相关文章:

apache - 为 SEO 和漂亮的 URL 重写 map

.htaccess - .htaccess 是否可以使用 3 个相同的参数?

html - 使用 htaccess rewrite 使子目录成为其自己的根目录以用于根相对路径请求

wordpress - 这个 .htaccess RewriteRule 中的单点有什么作用?

php - 如何在不编辑主文件的情况下在网站页面上添加当前版本号

python - 在 fedora 23 上安装 pip install psycopg2 时出错

c - 在 C 中的输入系统调用期间添加的额外字符串

Linux非su脚本间接触发su脚本?

php - mod_rewrite 我错过了什么?

php - 当 url 指向现有文件夹(无尾部斜杠)时如何重定向到 404。 HAproxy 或 mod-rewrite 相关