Search code examples
apache.htaccesshttp-redirecturl-rewritingsubdomain

Redirect all pages to subdomain while keeping the content


I want to redirect all my pages and video content to my sub domain (where I have my CDN)

currently I have link in a videogame, with people who generate traffic and I have a lot of link already in the game that I cant change since it will take forever, so I want redirect all people that will click on the link to my sub domain, where I have my CDN setup

https://exemple.com/folder/contents/video.mp4 TO https://cdn.exemple.com/folder/contents/video.mp4

I already try few rewrite command with htaccess but I get the error TOO_MANY_REDIRECT and I don't know what to do


Solution

  • This should work for you:

    RewriteEngine on
    
    RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
    RewriteRule ^(.+\.mp4)$ https://cdn.exemple.com/$1 [R,L]
    

    Put this at the top of your /root/.htaccess before other rules and make sure to Clear your browser cache before testing this new redirect.