2009-02-04 37 views
2

我有這個網址:如何在Apache mod中將字符從子域移動到文件名?

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

,並需要將其改寫爲:

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

能否請你告訴我,如果這是可能的嗎? 基本上我試圖將「X」(這是一個數字)從子域移動到文件名的末尾,就在擴展名之前。

謝謝。

回答

3

像這樣的東西應該這樣做:

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

但由於主機不同的是,這將導致外部重定向。

2

(未經測試)這樣的事情應該工作:

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

你需要通過的RewriteCond提取主機號。在重寫規則,你可以使用數字與%-modifier

HTH