我正在尝试创建与以下 URL 匹配的重定向规则:
en/property/rotterdam/apartment/lorem-ipsum-dolor-sit-amet/v-9/
en/property/rotterdam/apartment/lorem-ipsum-dolor-sit-amet/9/
en/property/rotterdam-centrum/appartment/lorem-ipsum-dolor-sit-amet/9
en/property/lorem-ipsum-dolor-sit-amet-9/
en/property/lorem-ipsum-dolor-sit-amet/v9/
en/property/lorem-ipsum-dolor-sit-amet/v-9/
en/property/lorem-ipsum-dolor-sit-amet/v-9
en/property/rotterdam/apartment/branch/lorem-ipsum-dolor-sit-amet-9/
en/property/rotterdam/lorem-ipsum-dolor-sit-amet-9/
en/property/rotterdam/lorem-ipsum-dolor-sit-amet-9434343/
en/property/rotterdam/apartment/lorem-ipsum-dolor-sit-amet/v-243249/
en/property/rotterdam/apartment/lorem-ipsum-dolor-sit-amet/v2342349/
en/property/rotterdam/apartment/lorem-ipsum-dolor-sit-amet/243249/
en/property/rotterdam/apartment/lorem-ipsum-dolor-sit-amet/v-9/
en/property/rotterdam/apartment/lorem-ipsum-dolor-sit-amet/v-9/?test=1
en/property/rotterdam/apartment/lorem-ipsum-dolor-sit-amet/v-9/test/one/?success=3
en/property/rotterdam/apartment/2-rooms/lorem-ipsum-dolor-sit-amet/v-9/blah/1234/blahh/55555/?sass=123
en/property/rotterdam/appartment/lorem-ipsum-dolor-sit-amet/9234234
en/property/rotterdam/lorem-ipsum-dolor-sit-amet/9234234
en/property/lorem-ipsum-dolor-sit-amet/9234234
en/property/9234234
en/property/rotterdam/appartment/lorem-ipsum-dolor-sit-amet/9/test/132?algo=123
所有需要匹配的网址都可以在这里看到
https://regex101.com/r/4TPEhy/1
我正面临两个问题,第一是两个 URL 不匹配:
en/property/rotterdam/apartment/2-rooms/lorem-ipsum-dolor-sit-amet/v-9/blah/1234/blahh/55555/?sass=123
en/property/9234234
第二个,正则表达式中的某些内容导致了内部重定向错误。
这是我的正则表达式(迄今为止我得到的最好的例子)
^(en\/)?property\/[A-Яa-я0-9\-_\/]+?([\d]+)(.*)$
这是我的重写规则
RewriteRule ^(en\/)?property\/[A-Яa-я0-9\-_\/]+?([\d]+)(.*)$ $1properties/property/$2$3&%{QUERY_STRING} [NC,L]
正则表达式似乎在工具(regex101)上运行良好,但当我尝试刷新应用该规则的页面时,我得到了一个500内部服务器错误。
我需要匹配所有的情况,我已经尝试了几个小时不同的组合,但我错过了导致这些问题的东西。
在 .htaccess 上,我需要的组是 $2 和 $3,因为 $2 包含我在脚本上使用的属性 ID,而 $3 是 URL 的其余部分,如任何其他额外参数或查询字符串。
之所以有这么多不同的配置,是因为用户可以设置自己的 URL 格式,但仅限于上面列出的选项。
这是请求此 URL 时从 apache 日志中提取的内容
https://localhost/en/property/rotterdam/apartment/lorem-ipsum-dolor-sit-amet/v-9/test/132?blah=123
日志
php74 | [Mon May 31 12:19:12.375537 2021] [rewrite:trace3] [pid 64] mod_rewrite.c(483): [client 172.18.0.1:63664] 172.18.0.1 - - [localhost/sid#7fd3d4ab1958][rid#7fd3d29d73c0/initial/redir#10] [perdir /var/www/html/] add per-dir prefix: en/properties/property/9/test/132&blah=123&blah=123&blah=123&blah=123&blah=123&blah=123&blah=123&blah=123&blah=123&blah=123&blah=123 -> /var/www/html/en/properties/property/9/test/132&blah=123&blah=123&blah=123&blah=123&blah=123&blah=123&blah=123&blah=123&blah=123&blah=123&blah=123