Jonathan Holvey Jonathan Holvey - 1 month ago 7
Apache Configuration Question

Any character match not working in Apache mod_rewrite RewriteRule

I'm trying to rewrite a URL on a website using Apache's

mod_rewrite
.

I have the following lines in a
.htaccess
file, which is in a folder
foo
in the server's root directory:

RewriteEngine On
RewriteBase /foo/

RewriteRule ^(.+)$ index.php?id=$1 [NC,L]


The idea is that everything after
foo/
in the URL
http://abc.example.com/foo/bar
is extracted and rewritten to
http://abc.example.com/foo/index.php?id=bar
, which I thought should be pretty straightforward - this isn't my first time using
mod_rewrite
.

I've tested this successfully on http://htaccess.madewithlove.be, however, I'm finding that on my server it will only work if I use
[a-z]+
instead of the wildcard
.+
in the rule. Otherwise the
id
parameter returns
index.php
.

Is there a problem with my rule declaration? If not, what configuration could be causing this behaviour, and how can I override it?

Answer

Worth a shot in case other rewrites are interefering, or by any chance you are rewriting into index.php by accident:

RewriteRule ^(?!index.php)(.*) index.php?id=$1 [NC,L]