Can't get this rewrite rule to work

(Jeff Karney) #1

I’ve been trying to get some rewrite rules working translated from Apache but for some reason I can’t get it it to work.

The Apache rules are…

RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+).html$ m/$2.php
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+).html$ m/$2/$3.php

I’ve translated that to…

rewrite {

            r ^\/m\/([a-zA-Z0-9_-]+)\.html$
            to /m/{1}.php

            r ^\/m\/([a-zA-Z0-9_-]+)\/([a-zA-Z0-9_-]+)\.html$
            to /m/{1}/{2}.php


So when I try to access /m/something.html it should rewrite to /m/something.php and the second rule… /m/foo/bar.html should translate to /m/foo/bar.php

However I just get a 404 when trying to access these URLs. From what I can tell everything looks correct but I must be missing something.

Any help would be appreciated.

(Matthew Fay) #2

Those rewrites look correct.

What’s your site’s root directive?

Does root + /m/foo/bar.php exist, and does Caddy have permission to read it?

(Jeff Karney) #3

Thank you for taking a look. Yes the root should be correct, I can access /m/foo/bar.php directly without a problem. Now that I have some verification the rewrites look correct I will keep digging. I’ll double check permissions and the root just in case.

(Matthew Fay) #4

One thing you might do to check that the rewrite is taking place is add {rewrite_uri} to your log directive format, then make a request that should be rewriten. You can then check what Caddy rewrote the request to.

(system) #5

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.