More than two variables in .htaccess

1

It's the first time I have to work with .htacces to make friendly URLs. With the following code I have been able to make this URL link become link

Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9/]+)$ index.php?c=$1 [L]

But, currently I have not been able to make it work for a second and third variable. For example with this URL link . How can it be done?

    
asked by Carlos Cespedes 18.10.2018 в 17:22
source

1 answer

1

It is simple, following the same example that you were already using, with a pattern by variable (adjust the presence of lowercase letters, capitals and numbers according to your needs). For example:

RewriteRule ^([a-z0-9-]+)/([a-zA-Z0-9-]+)/([a-z0-9-]+)$ index.php?c=$1&a=$2&id=$3 [L]

If it can be the case that you have 1, 2 or 3 variables in your urls, you must specify all the cases. It would be something like this:

RewriteRule ^([a-z0-9-]+)/([a-zA-Z0-9-]+)/([a-z0-9-]+)$ index.php?c=$1&a=$2&id=$3 [L]
RewriteRule ^([a-z0-9-]+)/([a-zA-Z0-9-]+)$ index.php?c=$1&a=$2 [L]
RewriteRule ^([a-z0-9-]+)$ index.php?c=$1 [L]

It would correspond to:

link

link

link

    
answered by 18.10.2018 / 17:39
source