redirect my site from www.foo.bar to cdn.foo.bar
is it possible to have an htaccess rule that will redirect my fil开发者_StackOverflow中文版es from
http://www.mydomain.com/page.html
to http://cdn.mydomain.com/page.html
but still making the link look like http://www.mydomain.com/page.html
I know masking urls isn't possible, but since they are on the same domain i was wondering if that was possible
Try these rules in your .htaccess file:
Options +FollowSymlinks -MultiViews
RewriteEngine on
# for http
RewriteCond %{HTTP_HOST} ^www.mydomain.com$ [NC]
RewriteCond %{SERVER_PORT} =80
RewriteRule ^(.*)$ http://cdn.mydomain.com/$1 [L,R]
# for https
RewriteCond %{HTTP_HOST} ^www.mydomain.com$ [NC]
RewriteCond %{SERVER_PORT} =443
RewriteRule ^(.*)$ https://cdn.mydomain.com/$1 [L,R]
However one caveat that it is an external redirect hence URL in your browser will change to http://cdn.mydomain.com/foo
because when you are jumping from one host to another you cannot have internal redirect hence R
flag is needed.
No idea about .htaccess but you could use a curl script in PHP.
精彩评论