Forum Moderators: phranque

Message Too Old, No Replies

a.domain.com/b ---> domain.com?pg=b&ref=a

         

azureus3

3:32 pm on Aug 10, 2010 (gmt 0)

10+ Year Member



Hi, I need some help with htaccess and mod_rewrite. I need this:
a.domain.com/b to be redirected to domain.com?pg=b&ref=a
- a must be a number or a single word
- b can be words with dashes (-) and numbers
I'm not really sure but I guess it's this regex: [0-9a-z\-A-Z]+

The problem with a is that the server probably thinks it's a folder (i don't rly know) so I get either some sort of "Domain not found" error or 404 error.

So far i have this:
#RewriteRule ^([0-9a-z\-A-Z]+)$ ./index.php?pg=$1

wildbest

3:55 pm on Aug 10, 2010 (gmt 0)

10+ Year Member



a.domain.com is one domain while domain.com is another domain. What of those domains is your hosting account for?

You get 404 Not Found, because you rewrite your requests at a.domain.com to a.domain.com/index.php?pg=$1. What is the first "." for in "./index.php?pg=$1"?

azureus3

5:03 pm on Aug 10, 2010 (gmt 0)

10+ Year Member



You get 404 Not Found, because you rewrite your requests at a.domain.com to a.domain.com/index.php?pg=$1.

So is it technically possible to redirect a.domain.com to domain.com?ref=a? Or not?

Oh and sorry, it wasn't 404 error but 410 error.

What is the first "." for in "./index.php?pg=$1"?
You can use index.php?pg=$1 it doesn't matter.

wildbest

8:56 pm on Aug 10, 2010 (gmt 0)

10+ Year Member



Yes, it is possible. If root for your .htaccess file is hosted under a.example.com rewrite rule for mod_rewrite should be something like this:

RewriteEngine On

RewriteCond $1 ^([0-9a-z\-A-Z]+)$
RewriteRule ^([0-9a-z\-A-Z]+)$ http://example.com?ref=$1 [R=301,L]

I say "something like this" because information you gave is insufficient. Most important point here is if you redirect URL from one domain to another domain, the second domain should be fully qualified.

If you don't want to use mod_rewrite you can use RedirectMatch like this:
RedirectMatch 301 ^([0-9a-z\-A-Z]+)$ http://example.com?ref=$1

azureus3

2:38 pm on Aug 11, 2010 (gmt 0)

10+ Year Member



Well that's the point - I don't have access to a.example.com and it doesn't even have to exist.

I only have access to example.com and I need the .htaccess file in example.com to redirect anything.domain.com to domain.com?ref=anything.

Is it possible?

wildbest

3:02 pm on Aug 11, 2010 (gmt 0)

10+ Year Member



If you have access to example.com DNS settings you can easily delete any unwanted sub-domains like a.example.com!

azureus3

4:24 pm on Aug 11, 2010 (gmt 0)

10+ Year Member



I don't want to delete anything. My question is if
a.domain.com/b can be redirected to domain.com?pg=b&ref=a.

azureus3

4:27 pm on Aug 11, 2010 (gmt 0)

10+ Year Member



The a should not be considered a subdomain but a part of the URL.

a can be anything (single word or number). Can you modify it using htaccess so the outcome will be GET parameter?

wildbest

5:19 pm on Aug 11, 2010 (gmt 0)

10+ Year Member



I only have access to example.com and I need the .htaccess file in example.com to redirect anything.domain.com to domain.com?ref=anything.

Is it possible?

No, it is not possible. What you want to achieve can be done by modifying .htaccess file on a.example.com but you don't have access to this resource. Case solved.

This can be accomplished by corresponding changes in Apache server config or virtual host files but can not be done with .htaccess rewrites.

jdMorgan

4:10 pm on Aug 12, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



"Domain not found" indicates that your DNS is not configured to recognize "wild-card" subdomains. The server will also have to be a name-based server (with a non-shared IP address) and it will also need to be configured to accept these wild-card subdomains.

The "x" in x.example.com is a subdomain of example.com, just like the "www" in www.example.com is a subdomain of example.com, because that is the definition of a subdomain.

Ask your host about a getting a "unique", "private", or "non-shared" IP address first. Typical additional cost in the U.S. is about $1.00 per month.

Jim