Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Subdomain rewrite

Quote Reply
Subdomain rewrite
I have gossamer links installed on the main folder of the website (www.mysite.com) . I opened a subdomain called sub.mysite.com
I want to manage a category called sub in this subdomain. Meaning that when the users enter sub.mysite.com there will be a rewrite for www.mysiye.com/sub
Any ideas?
Quote Reply
Re: [nir] Subdomain rewrite In reply to
Hi nir,

This works for me, give it a try :

RewriteEngine on

RewriteCond %{HTTP_HOST} sub.mysite.com [NC]
RewriteRule .* http://www.mysite.com/sub [R,L]

John
Significant Media

Last edited by:

Jag: Jun 20, 2006, 9:45 AM
Quote Reply
Re: [Jag] Subdomain rewrite In reply to
Thanks Jag :) I tried that. What happens is that when I enter the subdomain it redirects to the page I tried to do the rewrite on.
I want the page to look like it really sits in the subdomain, without redirect.
Quote Reply
Re: [nir] Subdomain rewrite In reply to
Hi nir,

In the code what can be called flags at the end indicate that in your list of conditions, this condition is the last with an 'L'. This can be interesting like with CSS since it can be like a cascading effect but it's easier to just place them accordingly and use the 'L'.
The other flag is 'R' which means redirect and as you say this will not give you the impression that you are still on the first URL typed since it redirects.

Just in case if you are trying to redirect to a script it is interesting to use the query string flag 'QSA' so you would have : [L,QSA]
For example some scripts can pick up the subdomain value passed on to it and then feed it to the script.

What I am curious about is if you are not using a redirect then are you going to be running static or dynamic pages in this folder since the mod_rewrite to simply redirect then no longer requires a mod_rewrite but if you have subsequent subfolders and/or scripts it could get pretty tricky.

I suggest you try using the the pass through flag [L,PT] but you may need to use another set of mod_rewrite conditions if you want to have files and folders in the subdomain folder.

John
Significant Media
Quote Reply
Re: [nir] Subdomain rewrite In reply to
Hi nir,

I just came across the below code on forums and unfortunately I only copied the code with a short sentence for me to remember what it should do, so I'm not sure where and when I got it, but it may help you :

This one uses a wildcard type system for subdomains and from memory I think it worked OK. I dropped it for only using one domain after having read an SEO article that indicated subdomains may dilute the ranking of a main domain.

You see that all dots are escaped so that instead of mysite.com you have mysite\.com, otherwise it will give you an error.

RewriteCond %{HTTP_HOST} !^(www\.)?mysite\.com$ [NC]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^([^\.]+)\.mysite\.com$ [NC]
RewriteRule .* /%1%{REQUEST_URI} [QSA,L]

I think this is what you are talking about i.e. redirecting a subdomain to a folder with the same name and 'should' redirect the subsequent requests while keeping the initial. I'm not sure this will work if you have complicated scripts running in the subdomain folder though... Give it a try and a) hope it works and b) hope it does what you want :)

John
Significant Media