HaLo2FrEeEk Posted June 2, 2009 Share Posted June 2, 2009 If the title wasn't descriptive enough, basically what I want to do is set up a subdomain on my server that contains all the media (videos) that I have uploaded, then use a .htaccess file with a mod_rewrite command to redirect anyone that tries to access a certain file in the existing folder to that file in the new subdomain. For example, if I have a video in /movies under my main domain directory, and the file is called somevideo.wmv, a person would currently access this file by going to http://mydomain.com/movies/somevideo.wmv. Well if I make a new subdomain, something like media.mydomain.com and put the videos in there, then when someone went to that URL above the file wouldn't be there anymore. I want to make a rewrite rule to make it so that if someone goes to http://mydomain.com/movies/somevideo.wmv it will redirect silently to media.mydomain.com/somevideo.wmv, is this as simple as I think it will be, an .htaccess file inside the /movies directory with this: RewriteRule (.*)\.[wmv|mpg|mpeg|mov|mp4] http://media.mydomain.com/movies/$1\.$2 [NR] Or something like that? I'm not that great at mod_rewrite and I wrote that all from scratch, so I'm sure it has errors, if someone could help me fix them. My main issue with that is what if someone puts in something like ../../ as the filename and tries to access files they shouldn't, in parent folders or something? Could they put something like http://mydomain.com/movies/../mydomain.com/index.php and download the index file from my main domain's directory? I don't want to try something like this in case it actually does that...but I might have to. Please, though, there's only so much I can test myself, not knowing that much about mod_rewrite, so can I get some help from the experts. Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/160601-securely-redirecting-to-another-directory-via-mod_rewrite/ Share on other sites More sharing options...
dreamwest Posted June 2, 2009 Share Posted June 2, 2009 Check if your server supports wildcard subdomains, this is one way of doing it http://anything.site.com If it does you should see http://site.com Quote Link to comment https://forums.phpfreaks.com/topic/160601-securely-redirecting-to-another-directory-via-mod_rewrite/#findComment-847663 Share on other sites More sharing options...
HaLo2FrEeEk Posted June 2, 2009 Author Share Posted June 2, 2009 I went to anything.mydomain.com and it gave me a 404 error. I don't think my server can do wildcard subdomains, but I'm not sure that would work for what I'm trying to do anyway. I figured it out though: RewriteRule (.*)\.(exe|scr|mp4|wmv|mov) http://media.mydomain.com/$1\.$2 will redirect properly, so all I have to do is move all the files from /movies into the new media subdomain, then put this in the movies folder (which I'm gonna keep for other things) in my main domain. I've tested it and it works great! Quote Link to comment https://forums.phpfreaks.com/topic/160601-securely-redirecting-to-another-directory-via-mod_rewrite/#findComment-847916 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.