LEGEND383 Posted June 15, 2011 Share Posted June 15, 2011 Hi all. I have been trying to figure this out for weeks, but have had no luck. Basically, I want some way of redirecting 'www.mysite.com/subdomain/subfolder/index.php' to 'subdomain.mysite.com/subfolder/index.php', and every way i have tried so far has not worked Any help would be greatly appreciated. Quote Link to comment Share on other sites More sharing options...
cags Posted June 16, 2011 Share Posted June 16, 2011 I'm going to go ahead and answer what you've asked, despite the fact I don't think it's what you really want. To redirect that first url to the second will depend on a few things, for instance whether subdomain is a complete wildcard or has a fixed number of values. Assuming it's a complete wildcard you can use something along the lines of... RedirectRule ^([^/]+)/([^/]+/[^/]*)$ http://$1.mysite.com/$2 [R=302,L] I suspect that there's a distinct possibility that what you really want to do (based on the fact it's far more common behaviour) is display the contents of that first page when somebody uses the second url, this is a whole different kettle of fish and would be done something roughly along the lines of... RewriteCond %{HTTP_HOST} ^([^.]+).mysite.com RewriteRule (.*) /%1/$1 [L] But note that you would need a wildcard dns record for subdomains for this to work. Quote Link to comment Share on other sites More sharing options...
LEGEND383 Posted June 17, 2011 Author Share Posted June 17, 2011 Thanks for the reply Allow me to try and explain a bit better. I have a subdomain set up (subdomain.example.com) and it works fine, except when its accessed using the folder instead of the subdomain (www.example.com/subdomain), which screws up the style, which is in the subdomain root and accessed via a html root folder reference (/style.css). The problem is when I access it from the folder (2nd example above), it loads the style for the main part of the site, which does not contain the right css classes (obviously) As mentioned, I need to force the use of the subdomain, redirecting the user to the subdomain if they don't use it themselves (which they should, as that's where all my links point) I have tried a few htaccess methods that claimed to keep the path intact, but they all redirected to the root of the subdomain EDIT: The subdomain isn't a wildcard, it is a set value Quote Link to comment Share on other sites More sharing options...
cags Posted June 18, 2011 Share Posted June 18, 2011 I guess I'm missing the point here then. If the folder is supposed to be accessed by the subdomin and looks wrong when accessed by the main domain, why is it accessible from outside the subdomain. Do you only have on vhost with the subdomain as an alias, or is the subdomains DocumentRoot inside the main domains? The simplest .htaccess hack to fix it would probably be to put a .htaccess file in the subdomain folder that checks the subdomain then redirects.... RewriteCond %{HTTP_HOST} ! ^subdomain.example RerwiteRule ^( .*)$ http://subdomain.example.com/$1 Quote Link to comment 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.