How to allow three optional parameters in the URL by .htaccess?

后端 未结 4 1938
一整个雨季
一整个雨季 2020-12-21 14:48

I have http://example.com and a PHP routing class that checks if some URL exists.
I want to make a new route, which is:

http://example.com/

4条回答
  •  礼貌的吻别
    2020-12-21 15:28

    You can handle the URI with php:

    .htaccess:

    RewriteEngine on
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^ index.php [L]
    

    php:

    if (isset($_SERVER['REQUEST_URI']))
    {
        $params = explode("/", ltrim($_SERVER['REQUEST_URI'], "/"));
        print_r($params);
    }
    

    example.com/just/these/params

    Output:

    Array
    (
        [0] => just
        [1] => these
        [2] => params
    )
    

提交回复
热议问题