.htaccess 重写删除字母



我有一个这样的网址:

http://www.example.com/296-large_default/james-bond.jpg

我需要重写为:

http://www.example.com/img/p/2/9/6/296.jpg

目前我正在使用这个规则,但不知何故我遇到了问题,任何线索为什么会发生这种情况?

RewriteRule ^([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+.jpg$ %{ENV:REWRITEBASE}img/p/$1/$1$2$3.jpg [L]

从以下格式的 URL 进行内部重写:

http://www.example.com/296-large_default/james-bond.jpg

http://www.example.com/img/p/2/9/6/296.jpg

请尝试以下操作:

RewriteRule ^(d)(d)(d)-[w-]+/[w-]+.jpg$ img/p/$1/$2/$3/$1$2$3.jpg [L]

这假设"id"(例如。 296 ( 始终为 3 位数字。无需在每个目录.htaccess文件中使用 URL 路径作为RewriteRule替换前缀。(没有名为"REWRITEBASE"的环境变量,除非您在某处明确设置了它。

最新更新