Turn text after slashes into variables using HTACCESS

I need to pass 3 variables with a url but with a slash. So, for example, I would use this URL:

http://www.example.com/variable1/variable2/variable3

I have this in my HTACCESS, which allows me to pass text after the first variable, but I cannot force the other two to go through even if I add & $ 2

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule /?([A-Za-z0-9_-]+)/?$ process.php?width=$1&height=$2 [QSA,L]

Any links or help would be great

+5
source share
2 answers

You only commit one variable in your rewrite rule.

You need something like:

RewriteRule ^([A-Za-z0-9_-]+)/([A-Za-z0-9_-]+)/([A-Za-z0-9_-]+)/?$ process.php?width=$1&height=$2&third=$3 [QSA,L]

or, a little shorter:

RewriteRule ^([\w-]+)/([\w-]+)/([\w-]+)/?$ process.php?width=$1&height=$2&third=$3 [QSA,L]

(a word symbol \wcontains letters, numbers, and underscores)

, -, 3 .

+5

.php, :

$pathinfo = isset($_SERVER['PATH_INFO'])
    ? $_SERVER['PATH_INFO']
    : $_SERVER['REDIRECT_URL'];

$params = preg_split('|/|', $pathinfo, -1, PREG_SPLIT_NO_EMPTY);

echo "<pre>";
print_r($params);

, script :

http://www.example.com/variable1/variable2/variable3

:

Array
(
    [0] => variable1
    [1] => variable2
    [2] => variable3
)

:

http://www.example.com/variable1/variable2/variable3 http://www.example.com/process.php/variable1/variable2/variable3

+6

All Articles