Search code examples
apachemod-rewriteurl-rewriting

Redirect rule not being followed


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.


Solution

  • 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?