如何在Apache mod rewrite中将字符从子域移动到文件名?

如何在Apache mod rewrite中将字符从子域移动到文件名?,apache,mod-rewrite,Apache,Mod Rewrite,我有这个网址: http://hostX.site.com/some_path_here/filename.jpg 需要将其改写为: http://host.site.com/same_path_here/filenameX.jpg 你能告诉我这是否可行吗? 基本上,我试图将“X”(它是一个数字)从子域移到文件名的末尾,就在扩展名之前 谢谢。(无需测试)类似的功能应该可以: RewriteCond %{HTTP_HOST} host(\d).site.com RewriteRule (.*)

我有这个网址:

http://hostX.site.com/some_path_here/filename.jpg
需要将其改写为:

http://host.site.com/same_path_here/filenameX.jpg
你能告诉我这是否可行吗? 基本上,我试图将“X”(它是一个数字)从子域移到文件名的末尾,就在扩展名之前

谢谢。

(无需测试)类似的功能应该可以:

RewriteCond %{HTTP_HOST} host(\d).site.com
RewriteRule (.*)\.(.*) host.site.com/$1%1.$2
您需要通过RewriteCond提取主机号。在“重写规则”中,可以将数字与%-修饰符一起使用


HTH

像这样的东西应该可以做到:

RewriteCond %{HTTP_HOST} ^host(\d)\.example\.com$
RewriteRule (.*)\.([^/.]+)$ http://host.example.com/$1%1.$2
但由于主机不同,这将导致外部重定向