Regex .htaccess重写带有点/句点的url问题

envsm3lx  于 2022-11-16  发布在  其他
关注(0)|答案(2)|浏览(138)

我打算重定向此URL:
http://localhost/iiif/http/image-service/papyrus,1/full/400,300/0/default.jpg

http://localhost/iiif/http/image.php?req=763648&id=papyrus,1&region=full&size=400,300&rotation=0&quality=default&format=jpg
重写规则如下:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /iiif/http/    
RewriteRule image-service/(.*)/(.*)/(.*)/(.*)/(.*).(.*)$ image.php?req=763648&id=$1&region=$2&size=$3&rotation=$4&quality=$5&format=$6 [R=301,NC,L,P]
</IfModule>

其结果是:

Array
(
    [req] => 763648
    [id] => papyrus,1
    [region] => full
    [size] => 400,300
    [rotation] => 0
    [quality] => default.jp.
)

而不是:

Array
(
    [req] => 763648
    [id] => papyrus,1
    [region] => full
    [size] => 400,300
    [rotation] => 0
    [quality] => default
    [format] => jpg
)

我怀疑这是由于网址中出现了句点/点(.)。我该如何纠正它呢?

dvtswwa3

dvtswwa31#

我建议你这样使用重写规则:

RewriteEngine on
RewriteBase /iiif/http/    
RewriteRule image-service/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/.]+)\.(.*)$ image.php?req=763648&id=$1&region=$2&size=$3&rotation=$4&quality=$5&format=$6 [NC,L,QSA]

明细:

  • 取反的字符类[^/]+,而不是可以匹配任何内容的贪婪.*
  • 从重写中删除R=301P标志,因为您需要的只是内部重写
  • 转义最后一个点以匹配扩展名
jm81lzqq

jm81lzqq2#

您需要转义文件扩展名前的句点

/(.*)/(.*)/(.*)/(.*)/(.*)\.(.*)

请注意,在最后两个(.*)捕获组之间添加了反斜杠\

相关问题