2014-05-17 65 views
1

在我htaccess文件我有:的.htaccess重寫一個文件到另一個 - 共存一般重寫

# 1) Redirect all non-www to www 

RewriteCond %{HTTP_HOST} !^www.mydomain.com$ [NC] 
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [L,R=301] 


# 2) Redirect all files in the root to equivalent files in the subfolder 
# at the same time changing all htm extension to html 

RewriteCond %{REQUEST_URI} !^/new/ 
RewriteRule ^(.*)\.htm$ /new/$1.html [L] 
RewriteCond %{REQUEST_URI} !^/new/ 
RewriteRule ^(.*)$ /new/$1 [L] 

現在我需要添加一個重寫條件的特定文件。 我將獲得的類型要求: http://www.mydomain.com/downloads/myfile1.zip

,我需要重寫: http://www.mydomain.com/new/downloads/myfile2.zip

你能告訴我哪個規則補充的嗎?

回答

1

您可以插入對於ZIP文件處理的新規則,然後在後續的規則添加例外zip文件:

RewriteCond %{HTTP_HOST} !^www\.mydomain\.com$ [NC] 
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [L,R=301] 

RewriteRule ^downloads/myfile1\.zip$ /new/downloads/myfile2.zip [L,NC,R=301] 

# 2) Redirect all files in the root to equivalent files in the subfolder 
# at the same time changing all htm extension to html 

RewriteCond %{REQUEST_URI} !^/(new/|myfile2\.zip) [NC] 
RewriteRule ^(.*)\.htm$ /new/$1.html [L] 

RewriteCond %{REQUEST_URI} !^/(new/|myfile2\.zip) [NC] 
RewriteRule ^(.*)$ /new/$1 [L] 
+0

對不起,我想你的解決方案,但似乎它不工作,也許我做了錯誤的適應我的真實情況。文件zip不在它們位於根目錄(舊文件)的下載子文件夾中的根文件夾中,也不在新子文件夾的下載子文件夾中(新文件) – user1238784

+0

ok現在嘗試更新代碼。 – anubhava

+0

謝謝,這工作。 – user1238784

相關問題