user5839 user5839 - 2 months ago 28
Apache Configuration Question

Rewrite folder to subdomain with htaccess for cross domain issues

I've followed the instructions in Rewrite folder to subdomain and I'm running into a problem

RewriteRule ^cdn/([^/]+)/?$ http://cdn.example.com/ [NC,R=301,L]


I'm expecting example.com/cdn/... to redirect to cdn.example.com but instead it's redirecting to cdn.example.com/cdn/.. which doesn't help me.

This attempt is to get around cross domain issues. Can anyone let me know how to make it rewrite how I need it, and also if this is likely to solve the video cross domain issues?

Answer

You lack $1 at the end of your RewriteRule. Also you need rules for cdn. subdomain to tell that all your content is in cdn folder:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^cdn\.example.com$ [NC]
RewriteRUle ^cdn - [L]
RewriteCond %{HTTP_HOST} ^cdn\.example.com$ [NC]
RewriteRUle ^(.*)$ cdn/$1 [L,NC]

RewriteCond %{HTTP_HOST} ^(www\.)?example.com$ [NC]
RewriteRule ^cdn/([^/]+)/?$ http://cdn.example.com/$1 [NC,R=301,L]
Comments