What's new

htaccess rewrite question

Oz.

Top Contributor
Hi

Can somebody help me write htaccess to do the following:

301 redirect:
domain1.com.au
domain2.com.au
domain-3.net.au
(anycombo).com.au
domain1.net.au
domain2.net.au
domain-3.net.au
(anycombo).net.au

to:
someotherdomain.com.au?domain=(as above .com.au/.net.au)


So
PHP:
http://yadayada.com.au would 301 redirect to
http://www.someotherdomain.com.au?domain=yadayada.com.au

http://www.yadayada.com.au would 301 redirect to
http://www.someotherdomain.com.au?domain=yadayada.com.au

http://DOMAIN-3.NET.AU would 301 redirect to
http://www.someotherdomain.com.au?domain=domain-3.net.au

Thanks much.
 

FirstPageResults

Top Contributor
Just replace %{HTTP_HOST} with the domain, I only added that for convenience and reusability

I think that's what you mean..
 

Oz.

Top Contributor
The domain is the variable, so can't be hardcoded so to speak.
eg:
PHP:
BOTH http://yadayada.com.au AND http://www.yadayada.com.au would 301 redirect to
http://www.someotherdomain.com.au?domain=yadayada.com.au
and
http://www.DOMAIN-3.NET.AU would 301 redirect to
http://www.someotherdomain.com.au?domain=domain-3.net.au

so, your suggestion does the above (BUT I need it to also strip the subdomain away from the variable [domain=%{HTTP_HOST}], eg: www in the above examples):
PHP:
RewriteRule ^(.*)$ http://www.someotherdomain.com.au?domain=%{HTTP_HOST} [R=301,L]

Ideally I need the one rule for many domains, otherwise it will be a pain to replicate on a per domain basis.

Hope that makes sense. Anyway, really appreciate your help! Thanks mate.
 

johno69

Top Contributor
What if you don't redirect, but park and use the "Current domain" as a variable on the page?

Essentially it's the same thing. I'm assuming you are creating a for sale page and want to know the domain they used to get there and pass that through a form?

I might totally be on the wrong path here. But I have a solution for you if that is what you are trying to do.
 

johno69

Top Contributor
File will need to be php. Line 1 put:

PHP:
<?php $CurrentDomain = str_replace("www.", "", $_SERVER['HTTP_HOST']); ?>

Then where you want the current domain to be used put the variable:

PHP:
<?php echo $CurrentDomain; ?>

You can use that to show the domain on the page too, like welcome to < domain >

Also if you want to set a price, or logo etc for each specific domain use:

PHP:
Our price:
	<?php
	switch ($CurrentDomain) {
			case "domain1.com":
			$DomainPrice = 495;
			break;
			case "domain2.com":
			$DomainPrice = 550;
			break;
			default:
			$DomainPrice = 299;
			break;
				}
	echo  '$' . $DomainPrice;
	?> USD

You can repeat the case -> break part for each domain you want to target.

The default part is the fallback. Should it be a domain not listed then show this.

You can of course edit the USD part.

I use it for a few domains I have all parked together like these, I use this system to change the logo out etc.

See it in action:

Wollongong Painting | Painting in the Wollongong area
Wollongong Electrical | Electrician in the Wollongong area

as well as a few others.
 

Oz.

Top Contributor
Thanks much Johno, and FPR...got it working beautifully with a combination of both your answers. Really appreciate it guys!
 

Community sponsors

Domain Parking Manager

AddMe Reputation Management

Digital Marketing Experts

Catch Expired Domains

Web Hosting

Members online

No members online now.

Forum statistics

Threads
11,106
Messages
92,078
Members
2,394
Latest member
Spacemo
Top