【发布时间】:2016-12-13 11:44:37
【问题描述】:
我有一个包含大量图片和静态内容的现有网站。我现在已经注册了 MaxCDN,需要将静态内容重定向到他们的 cdn。
我想要一个 htaccess 规则,它将检测像 array('css', 'js', 'jpg', 'jpeg', 'png' 'gif','pdf') 这样的文件扩展名并重定向到 cdn url。
示例: 普通网址:https://www.example.com/uploads/slider/1470903158.jpg CDN网址:https://www.cdn.com/uploads/slider/1470903158.jpg
我已经为我的区域定义了 CDN url。我会使用 corebase_url() 覆盖来执行相同的功能,但不幸的是该网站不在 CI 中,重新开始是不可行的。我认为在当前情况下使用 .htaccess 将是我最好的选择。不幸的是,我对 .htacces 几乎一无所知。
这是我当前的 .htaccess 文件
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Removes index.php from ExpressionEngine URLs
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule (.?)index\.php/(.*) /$1$2 [R=301,NE,L]
# Directs all EE web requests through the site index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
# BEGIN Expires
<ifModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 seconds"
ExpiresByType text/html "access plus 1 seconds"
ExpiresByType image/gif "access plus 2592000 seconds"
ExpiresByType image/jpeg "access plus 2592000 seconds"
ExpiresByType image/png "access plus 2592000 seconds"
ExpiresByType text/css "access plus 604800 seconds"
ExpiresByType text/javascript "access plus 216000 seconds"
ExpiresByType application/x-javascript "access plus 216000 seconds"
</ifModule>
# END Expires
#The following line is enough for .js and .css
AddOutputFilter DEFLATE js css
#The following line also enables compression by file content type, for the following list of Content-Type
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml
#The following lines are to avoid bugs with some browsers
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary: Accept-Encoding
【问题讨论】: