0

I have set up the following conf files for my apache site and enabled mod rewrite, but I'm having issues getting the rule to fire. I'm fairly confident it's a missed configuration, but I'm not sure where it lies. I have been experimenting with different configurations but can't find one that works

My apache2.conf file contains the following

<Directory /var/www/html>
    Options Indexes FollowSymLinks
    AllowOverride FileInfo
    Require all granted
</Directory>

My 000-default.conf file contains the following

<VirtualHost *:80>
    DocumentRoot /var/www/html

    RewriteEngine On
    RewriteRule ^/Foo/([A-Za-z0-9]+)/([A-Za-z0-9]+)$ /Baz/$1/Bar/$2/json

</VirtualHost>

If I go to : http://localhost/Foo/sample/data

The error in the logs:

 File does not exist: /var/www/html/Foo/sample/data

However, if i manually go to /Baz/sample/Bar/data/json, I get a 200.

EDIT: regex was wrong. fixed but issue still occurs.

Morcalavin
  • 142
  • 2
  • 9

1 Answers1

0

Looks like maybe a missing bracket in your groups:

this:

^/Foo/(A-Za-z0-9]+)/(A-Za-z0-9]+)$

should be:

^/Foo/([A-Za-z0-9]+)/([A-Za-z0-9]+)$

This kind of error typically causes the server to complain about malformed configuration. Have you checked the server logs?

Slawomir Chodnicki
  • 1,525
  • 11
  • 16
  • Fixed, but unfortunately the same issue still persists. – Morcalavin May 30 '19 at 13:28
  • I'm accepting this as the answer, since it was indeed an error on my part. However, the final fix that made everything work for me was adding [PT] on the end of the rule. Without it it was trying to serve up a file, instead of trace back the url to the correct location. – Morcalavin May 30 '19 at 15:16
  • More details about [PT] RewriteFlag can be found in [https://httpd.apache.org/docs/2.4/rewrite/flags.html#flag_pt](https://httpd.apache.org/docs/2.4/rewrite/flags.html#flag_pt) – Giri May 31 '19 at 06:27