I have two rules that currently function as they should, but I feel like they can be consolidated into one for the benefit of a smaller config to maintain and less rules to process for each HTTP request. The rules:
RewriteRule ^/user/[0-9]+/?$ /index.php [NC,QSA,L]
RewriteRule ^/user/[0-9]+/(.*)$ /$1 [NC,QSA,L]
I had to add the first rule with an explicit redirect to /index.php
because going to http://www.example.com/user/5/
, for example, would give me an HTTP 400. The rewrite would internally rewrite to /
, but instead of reading the DirectoryIndex, index.php
, the error_log would give me: client denied by server configuration: /
.
Adding the explicit redirect to /index.php
fixed URLs such as http://www.example.com/user/5/
and the second rule would work for everything else.
Is there a way to set the config to just normally use the DirectoryIndex
I have set and not explicitly list index.php here? http://www.example.com
works just fine without the rewrite rules, so I'm not entirely sure why a rewrite would break it.