2011-09-23 91 views
1

如果客戶端請求* .pdf或* .cdr文件,我想重定向到另一個站點(存儲)。htaccess在某些文件擴展名上重定向到另一個站點

問題是,用下面的htaccess,cdr下載工程,但不是pdf。 如果更改規則順序(cdr優先,pdf第二),那麼pdf的作品,但不是CDR。

我試過[OR],其他正則表達式在一種模式下捕獲兩個擴展。這是唯一有效的作品(半作品)。 重定向點存在的文件(pdf或cdr)(我通過FTP檢查)。

我現在有根的.htaccess:

#<snip> 

RewriteCond %{REQUEST_FILENAME} -s [OR] 
RewriteCond %{REQUEST_FILENAME} -l [OR] 
RewriteCond %{REQUEST_FILENAME} -d 

# catch site.ro/some_file.pdf 
RewriteCond %{REQUEST_URI} (.+pdf)$ [NC] 
RewriteRule ^(.*)$ http://docs.site.com/$1 [L,R] 

# catch site.ro/some_file.cdr 
RewriteCond %{REQUEST_URI} (.+cdr)$ [NC] 
RewriteRule ^(.*)$ http://docs.site.com/$1 [L,R] 

RewriteRule ^.*$ - [NC,L] 
RewriteRule ^.*$ index.php [NC,L] 

回答

1

這是我會做:

RewriteCond %{REQUEST_FILENAME} !-d    # If not an existing directory 
RewriteCond %{REQUEST_FILENAME} !-f    # If not an existing file 
RewriteCond %{REQUEST_URI} \.(pdf|cdr)$ [NC]  # If filename ends with .pdf or .cdr 
RewriteRule ^(.*)$ http://docs.site.com/$1 [L,R] # Redirect the user to the other site 

RewriteRule ^.*$ index.php [NC,L]  # Redirect all other requests to index.php 

希望這有助於你

+0

好了,現在他們沒有工作。 – nevvermind

+1

取消。這工作。謝謝。 – nevvermind

相關問題