Php htaccess重写
我目前正试图重写一些URL,它们都遵循基本格式 这是当前的.htaccess规则Php htaccess重写,php,.htaccess,Php,.htaccess,我目前正试图重写一些URL,它们都遵循基本格式 这是当前的.htaccess规则 RewriteRule ^([A-Za-z]+)/([A-Za-z]+)$ index.php?d=$1&n=$2 [QSA] 有时,会有一些链接,例如 /用户/配置文件/用户ID=2 但是,编写规则是为了重写 /用户/配置文件 作为 php?d=users&n=profiles 如何更改规则,使其可以选择性地接受和添加额外参数?下面的规则将users/profiles/userid=2重写为index.
RewriteRule ^([A-Za-z]+)/([A-Za-z]+)$ index.php?d=$1&n=$2 [QSA]
有时,会有一些链接,例如
/用户/配置文件/用户ID=2
但是,编写规则是为了重写
/用户/配置文件
作为
php?d=users&n=profiles
如何更改规则,使其可以选择性地接受和添加额外参数?下面的规则将
users/profiles/userid=2
重写为index.php?d=users&n=profiles&userid=2
。经过测试,工作正常
RewriteRule ^([a-z]+)/([a-z]+)/([a-z]+)=(\d+)$ index.php?d=$1&n=$2&$3=$4 [NC,QSA,L]
如果您将上述规则添加到现有规则之上,它们都将很好地发挥作用(我对现有规则进行了一些修改):
我还没有测试,但我认为这应该可以:
RewriteRule ^([A-Za-z]+)/([A-Za-z]+)/(.*)$ index.php?d=$1&n=$2&$3 [QSA]
这:
/users/profiles/userid=2&something=3
应该变成这样
index.php?d=users&n=profiles&userid=2&something=3
,如果没有其他参数,则会将其终止。您应该将此规则与以前的规则结合使用@LazyOne已经向您解释了一切:)不要删除您以前的规则,只需将此规则添加到下面(或上面)——请参阅更新的答案。
RewriteRule ^([A-Za-z]+)/([A-Za-z]+)/(.*)$ index.php?d=$1&n=$2&$3 [QSA]