0

I am trying to make a scalable RewriteRule on my .htaccess, I use each word before slash as a parameter.

for example: http://localhost/mysite/param1/param2/param3/.../param20

I am working with this code (but if I want 6 o 7 parameters, it would be too long):

Options +FollowSymLinks
RewriteEngine   on

DirectoryIndex  web.php?param1=inicio

RewriteRule ^([a-zA-Z0-9_-]+)$                      web.php?param1=$1
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$     web.php?param1=$1&param2=$2

Next rewriteRules would be longer ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$/([a-zA-Z0-9_-]+)$/([a-zA-Z0-9_-]+)$/([a-zA-Z0-9_-]+)$ web.php?param1=$1&param2=$2&param3=$3&param4=$4&param5=$5

I send each parameter to php as an indivudal variable, and I use the first parameter to decide wich page must be shown on web.php. Is there any way to make it shorten? I don't know how to optimize it. I don't even know if I am on the right way. How would you make it? Maybe using php? Thanks.

1 Answer 1

1

You should not do parameter parsing within a RewriteRule, except if you have a small fixed number of parameters (like MediaWiki does).

Instead, redirect every request (or a subset of them based on the first characters of the URL for example) to a PHP script which will do the parsing of the URL itself. It would then display the correct page based on what it parsed.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .