当前位置: 动力学知识库 > 问答 > 编程问答 >

How to move a char from the subdomain to the filename in Apache mod rewrite?

问题描述:

I have this URL:

http://hostX.site.com/some_path_here/filename.jpg

and need to rewrite it to:

http://host.site.com/same_path_here/filenameX.jpg

Can you please tell me if this is possible?

Basically I am trying to move "X" (it is a number) from the subdomain to the end of the filename, just before the extension.

Thanks.

网友答案:

Something like this should do it:

RewriteCond %{HTTP_HOST} ^host(\d)\.example\.com$
RewriteRule (.*)\.([^/.]+)$ http://host.example.com/$1%1.$2

But since the host is different, this will cause an external redirect.

网友答案:

(Without testing,) something like this should work:

RewriteCond %{HTTP_HOST} host(\d).site.com
RewriteRule (.*)\.(.*) host.site.com/$1%1.$2

You need to extract the host number through the RewriteCond. In the RewriteRule you can use the number with the %-modifier

HTH

分享给朋友:
您可能感兴趣的文章:
随机阅读: