Jump to content

how to force use of subdomain


LEGEND383

Recommended Posts

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.

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

Thanks for the reply :D 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 :confused:

 

EDIT: The subdomain isn't a wildcard, it is a set value

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.