简体   繁体   中英

mod_rewrite - htaccess - more than one Parameter

I have a URL like this:

https://example.com/folder/j/i?param1=123&param2=456

I have a physical folder folder , everything after folder should be GET-Parameters, so I get this in PHP:

<?php
$mode = $_GET["mode"]; // j
$type = $_GET["type"]; // i
$param1 = $_GET["param1"] // 123
$param2 = $_GET["param2"] // 456

At the moment I tried something like that:

RewriteEngine On
RewriteBase /folder
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?mode=$1& [L,QSA]

I don't get, how do I call more than one Parameter?

Thank you!

Inside /folder/.htaccess you can have this rule:

RewriteEngine On
RewriteBase /folder/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?mode=$1&type=$2 [L,QSA]

This will route https://example.com/folder/j/i?param1=123&param2=456 to https://example.com/folder/index.php?mode=j&type=i&param1=123&param2=456

更好的方法是使用PHP以“ /”作为分隔符来分解 GET参数。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM