I’m trying to setup some basic .htaccess
rewrite rules for my Replit PHP repl/project. Like rewriting /foobar/123 to /foobar.php?id=123
.
I have created a new .htaccess
file and I dare to say my rewrite code is correct. But it isn’t working, instead my
requests seem to go to index.php
with no query parameters added. That behaviour is the same whether I disable my .htaccess
rules or not.
RewriteEngine On
# /ID to index.php?id=ID
RewriteRule ^([0-9a-k]{1,12})$ index.php?id=$1 [L]
# /ID/FILENAME.EXT to contents.php?id=ID&name=FILENAME.EXT
RewriteRule ^([0-9a-k]{1,12})/([^/&?]+)$ contents.php?id=$1&name=$2 [L]
Test results:
/abcxyz -> index.php
/abc/xyz -> index.php
/abc.html -> 404
/abc.xyz -> 404
/abc. -> 404
/abc?id=123 -> index.php?id=123
/abc.xyz?id=123 -> 404
I think maybe the PHP motor behind repl doesn’t use or support .htacess
files. But I can’t find any documentation on .htaccess
use or anything related to rewriting.
The Replit documentation is very sparse and when choosing “I need help with how to use Replit” they redirect to Stack Overflow! Here I am…
My needs are:
- Rewrite
^([0-9a-k]{1,12})$
toindex.php?id=$1
. - Rewrite
^([0-9a-k]{1,12})/([^/&?]+)$
tocontents.php?id=$1&filename=$2
.
The first one I probably can do via reading request url from index.php
or something? The second one needs to support paths with file extensions and it doesn’t seem possible with the functionality I’ve found from my testing.