Forum Moderators: phranque

Message Too Old, No Replies

Subdomain.Site1.com to Site2.com/Subdomain

Yet another Rewrite/htaccess Question

         

Schorhr

11:27 am on May 12, 2005 (gmt 0)

10+ Year Member



Hello,
I own two domains,
wap.cc and nottoxic.com.

Due to my webhosts expensive cc-Conditions I moved wap.cc to a different host (a Domain-only package with 15 Subdomains).

I googled a bit and found several scripts for using htaccess and rewrite to redirect catch all ("*")Domains to a folder or script, such as
subdomain.site.com -> site.com/subdomain.

The trouble now is that I am not good at modrewrite nor can I get scripts to work that I found while using google yesturday.

I suppose I would have to use something like http_referer instead of host due to the fact that the first domain is redirecting, and thats where it seem to fail. Yesturday around 1 or 2 am it seemed like I have got something working, though it ended up an a endless loop of redirection, though when deleting the htaccess-file via ftp it ended up in the right subdir.

I would be greatfull for any advice!

-tanks in advance
Marcus

jdMorgan

6:20 pm on May 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Marcus,

Welcome to WebmasterWorld!

Please post you best-effort code so we can discuss it.

More information on mod_rewrite and regular expressions are cited in our Forum Charter [webmasterworld.com]. The Charter and our Terms of Service [webmasterworld.com] describe how we do things here.

HTTP_REFERER is not reliable enough for your application, so I suggest you create and use easily-identifiable URLs on the 'new' server that will unabiguously identify the request as being from the 'old' server. The simplest way might be to add a query string to the URLs (links) on the pages on the 'old' server, and then recognize that URL on the new server, and rewrite it if required.

Jim

Schorhr

10:59 am on May 13, 2005 (gmt 0)

10+ Year Member



Thanks for your reply!

Well, the code I had somewhat success with is lost, in a 1 o'clock frustration I rewrote it to bits...
The Script I used as basis was a combination of the ideas at
[modwest.com...]
and other Tutorialsites & Messageboards.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^([a-z0-9]+)\..+\..*$ [NC]
RewriteCond /full/path/to/homedirectory/htdocs/%1!-d
RewriteCond /full/path/to/homedirectory/htdocs/%1!-l
RewriteRule ^(.*)$ [yourwebsite.com...] [L,NS]
(bzw. RewriteRule ^(.*)$ [yourwebsite.com...] )

But with the fact that http_referer is unreliable, (I suppose its submited from the clients browser, IF it is submited at all) makes this atempt useless.
The thing is I only have 0.5 MB space and 20 MB of Transfer at my CC-Domain Host since its only a Domain-Package. I understand now that the best thing would be to put a htaccess at the Domain-Webspace and redirect subs.wap.cc to nottoxic.com/subs from there so I do not have to use http-referer? Any idea if this will produce traffic?

jd01

8:13 am on May 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Marcus,

I'm not sure I really understand what your are trying to do... Is it to serve the information to the sub-domain(s) from the main directories, or externally redirect them to it?

RewriteEngine on
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www.yourdomain.com [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.yourdomain.com [NC]
RewriteRule ^(.*) http://www.yourdomain.com/script.php?sub=%1 [R=301,L]

Or, something close, should work for an external, permanent redirect.
Cond 1: check to see there is a host defined.
Cond 2: only continue if the sub-domain is not www.
Cond 3: 'catch' anything before the .(dot) and store it in a variable.
Rule: store everything from the path in a variable... Then redirect everything to the http path and add the stored sub-domain as the query string.

Unfortunately, I don't know what you are going to do with the sub-domain directory path, so I have no idea of what type of regular expression you need to make it work... or, where to put the variables that are stored in it.

To redirect silently, or internally... something close to the same should work, as long as your directories are all in the same root on the same server. (If not see the [P]-proxy flag documentation to serve the information silently via proxy pass through, using the above ruleset.)

RewriteEngine on
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www.yourdomain.com [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.yourdomain.com [NC]
RewriteRule ^(.*) /path/to/script.php?sub=%1 [L]

Sorry for the long response time.

Hope this helps.

Justin

Schorhr

5:56 pm on May 23, 2005 (gmt 0)

10+ Year Member



Hi, thanks for your reply and sorry for my late reply.
The thing is that I have two domains, one with webspace, one without. I want to redirect from
subs.nospace.tld to myspace.tld/go.php?id=subs which does not work.

I did try your script but i suppose I would need to work with http_referrer which is not reliable.

Too bad I did not look ahead before registering, though now I at least have the domain hosted dirt-cheap.