简体   繁体   English

mod_rewrite-htaccess-多个参数

[英]mod_rewrite - htaccess - more than one Parameter

I have a URL like this: 我有这样的网址:

https://example.com/folder/j/i?param1=123&param2=456 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: 我有一个物理文件夹folder ,后面的所有folder应该是GET参数,所以我得到这个在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: /folder/.htaccess您可以使用以下规则:

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 这会将https://example.com/folder/j/i?param1=123&param2=456路由到https://example.com/folder/index.php?mode=j&type=i&param1=123&param2=456

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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