简体   繁体   中英

Apache2 mod_rewrite not working on nested folders

I'm trying to setup mod_rewrite on a small VPS running Ubuntu 18.04 with Apache 2.4.29

I have the following structure:

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

I'm using it as a hobby and learning the works of it. The issue is the following:

I've added a few RewriteRule's in apache2.conf file in /etc/apache2/

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

The first one that rewrites /test.php to /test works without any problems. The second one that i'd wish would rewrite the entire /tools/php/index.php to a simple /php doesn't seem to work and I haven't figured out why, after countless 'solutions' found on Google.

This is the exact lines i have in the Directory tag in 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>

Any help is much appreciated as I'm stuck right now and unless i stumble upon a good solution, I don't know how much it will take me to fix this.

Cheers, G.

I managed to find the issue to this problem.... fairly quicker than I anticipated.

The problem was that besides the RewriteRule's I had in apache2.conf, before that I had created a .htaccess file within the root directory which was blocking the previous RewriteRule's.

After removing .htaccess file there everything seems to work ok -> I will try to use that .htaccess file as I think it would be better for the overall structure of the project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM