Regex 使用两个get参数重写规则

Regex 使用两个get参数重写规则,regex,.htaccess,mod-rewrite,parameters,get,Regex,.htaccess,Mod Rewrite,Parameters,Get,我的文件夹/文件结构如下: www.example.com/a/<optional subfolder>/file.png 应该改写为 www.example.com/file.php?user=a&file=file.png www.example.com/file.php?user=a&file=random/subfolders/here/file.png 及 将改写为 www.example.com/file.php?user=a&file=fi

我的文件夹/文件结构如下:

www.example.com/a/<optional subfolder>/file.png
应该改写为

www.example.com/file.php?user=a&file=file.png
www.example.com/file.php?user=a&file=random/subfolders/here/file.png

将改写为

www.example.com/file.php?user=a&file=file.png
www.example.com/file.php?user=a&file=random/subfolders/here/file.png

我在互联网上找到了很多重写规则,其中一个规则甚至有效,但不适用于子文件夹。由于我对RegEx一无所知,我非常感谢您的帮助^^

尝试将此规则添加到文档根目录中的htaccess文件中:

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