0

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.

George
  • 35
  • 6
  • See also: [rewrite log](https://stackoverflow.com/questions/9632852/how-to-debug-apache-mod-rewrite) – mario Feb 14 '19 at 12:45
  • _"doesn't seem to work"_ - so what exactly happens? Just a 404 message or some other error? – M. Eriksson Feb 14 '19 at 12:49
  • Yes, when trying to access www.host.com/php I get a 'Not found error' - When I try to access www.host.com/test I get the contents of test.php file. – George Feb 14 '19 at 12:54

1 Answers1

0

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.

George
  • 35
  • 6