【问题标题】:Apache2 mod_rewrite not working on nested foldersApache2 mod_rewrite 不适用于嵌套文件夹
【发布时间】:2019-07-08 11:52:13
【问题描述】:

我正在尝试在运行 Ubuntu 18.04 和 Apache 2.4.29 的小型 VPS 上设置 mod_rewrite

我有以下结构:

root
├── index.html
├── resources
│   └── css
│       └── styles.css
├── test.php
└── tools
    └── php
        └── index.php

我将它作为一种爱好并学习它的作品。问题如下:

我在 /etc/apache2/ 的 apache2.conf 文件中添加了一些 RewriteRule

RewriteRule ^test$ /test.php [L]
RewriteRule ^php$ /tools/php/index.php [L]

第一个将 /test.php 重写为 /test 的方法没有任何问题。我希望的第二个将整个 /tools/php/index.php 重写为一个简单的 /php 似乎不起作用,在 Google 上找到无数“解决方案”之后,我还没有弄清楚原因。

这是我在 apache2.conf 目录标签中的确切行

<Directory /home/user/Work/Web/root>
    Options +Indexes -MultiViews +FollowSymLinks
    AllowOverride All
    Require all granted
    RewriteEngine on
    RewriteRule ^test$ /test.php [L]
    RewriteRule ^php$ /tools/php/index.php [L]
</Directory>

非常感谢任何帮助,因为我现在被卡住了,除非我偶然发现一个好的解决方案,否则我不知道要花多少时间才能解决这个问题。

干杯, G.

【问题讨论】:

  • 另见:rewrite log
  • “似乎不起作用” - 那么到底发生了什么?只是 404 消息还是其他错误?
  • 是的,当我尝试访问 www.host.com/php 时出现“未找到错误” - 当我尝试访问 www.host.com/test 时,我得到了 test.php 的内容文件。

标签: php apache mod-rewrite apache2 ubuntu-18.04


【解决方案1】:

我设法找到了这个问题的问题......比我预期的要快。

问题在于,除了我在 apache2.conf 中的 RewriteRule 之外,在此之前我在根目录中创建了一个 .htaccess 文件,它阻止了以前的 RewriteRule。

删除 .htaccess 文件后,似乎一切正常 -> 我将尝试使用该 .htaccess 文件,因为我认为这对项目的整体结构会更好。

【讨论】:

    猜你喜欢
    • 2010-12-20
    • 2013-11-09
    • 1970-01-01
    • 2016-10-15
    • 1970-01-01
    • 2013-07-25
    • 1970-01-01
    • 2012-05-30
    • 1970-01-01
    相关资源
    最近更新 更多