.htaccess重写查询字符串的规则路径

.htaccess重写查询字符串的规则路径,.htaccess,mod-rewrite,.htaccess,Mod Rewrite,我正在努力实现像这样的url example.com/path1到example.com/index.php?p1=path1 example.com/path1/path2到example.com/index.php?p1=path1&p2=path2 在我的.htaccess中,我有: 重新启动引擎 RewriteRule^(.*)/(.*)$/index.php?c=$1&g=$2[NC,L] RewriteRule^([a-zA-Z0-9-\]+)$/index.php?g=$1[NC,

我正在努力实现像这样的url

example.com/path1到example.com/index.php?p1=path1

example.com/path1/path2到example.com/index.php?p1=path1&p2=path2

在我的.htaccess中,我有:

重新启动引擎

RewriteRule^(.*)/(.*)$/index.php?c=$1&g=$2[NC,L]

RewriteRule^([a-zA-Z0-9-\]+)$/index.php?g=$1[NC,L]

它适用于example.com/路径1/路径2的情况,但对于example.com/路径1的情况,它仅在url中没有点时才起作用。例如,我想让example.com/mydomain.com工作到example.com/index.php?g=domain.com,但我无法让它工作


你能帮我一下吗?

以下是我的处理方法:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?params=$1
然后,无论您使用什么服务器端语言,我都将使用PHP parse$\u GET['param']

$params = explode('/', $_GET['params']);

使用
([a-zA-Z0-9-畷]+)
只显式处理字母数字加下划线的情况。这将排除您的示例案例。在重写时,您甚至不需要通过
参数
变量,只需使用
$\u服务器['REQUEST\u URI']
-这使规则更加简洁/index.php[L,QSA]非常感谢,它起了作用,我用这种方式解决了这个问题!