URL redirecting

Shibbi90

Regular Member
Joined
Mar 3, 2011
Messages
484
Reaction score
236
Hey,

I have multiple domains pointing to the same WP install. As of now you will see the same domain in the address bar as the one you click. Is there any way of showing only the main URL no matter what domain the visitors used to get to my website?

I know I can use HTTP redirect with namecheap, but I don't really want to do that. I am currently using cloudflare as my DNS provider.

I have tried 301 URL redirect with page rules on CloudFlare but I can't seem to get it working.

Any help would be appreciated :)
 
In the .htaccess file in each of the folders for each domain, create a 301 redirect to the main domain.
 
you can add the domains in your cpanel and use redirect option from there
 
<?php
if(isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] != "http://www.bad.com"){
$url = $_SERVER['HTTP_REFERER'];
}else{
$url = "Http://www.good.com";
}

header("Location: ".$url);
?>

This is totally doable, but it's way slower than doing it at a lower layer such as .htaccess. At the application layer, you have to load up a lot more infrastructure before the redirect finally takes place.
 
This is totally doable, but it's way slower than doing it at a lower layer such as .htaccess. At the application layer, you have to load up a lot more infrastructure before the redirect finally takes place.
Do you have an example for 301 redirect with .htaccess or a link for more info? :) Total newbie here. Googling as we speak
 
This is totally doable, but it's way slower than doing it at a lower layer such as .htaccess. At the application layer, you have to load up a lot more infrastructure before the redirect finally takes place.
Speed is milosecounds these days ....both header solution , in fact php might be quicker if wp being used .
 
Speed is milosecounds these days ....both header solution , in fact php might be quicker if wp being used .
I agree that the difference would be milliseconds, but there is absolutely, literally no way a PHP redirect can be faster than an htaccess redirect. When the connection comes into the server, it checks htaccess, then proceeds to execute the application layer which includes creating the PHP session, etc. WordPress would have no bearing on whether PHP is faster. In fact, most plugins such as Yoast, handle the redirects inside the .htaccess file.
 
I agree that the difference would be milliseconds, but there is absolutely, literally no way a PHP redirect can be faster than an htaccess redirect. When the connection comes into the server, it checks htaccess, then proceeds to execute the application layer which includes creating the PHP session, etc. WordPress would have no bearing on whether PHP is faster. In fact, most plugins such as Yoast, handle the redirects inside the .htaccess file.
Give me that brain lol , i agree you win lol interesting cheers
 
I agree that the difference would be milliseconds, but there is absolutely, literally no way a PHP redirect can be faster than an htaccess redirect. When the connection comes into the server, it checks htaccess, then proceeds to execute the application layer which includes creating the PHP session, etc. WordPress would have no bearing on whether PHP is faster. In fact, most plugins such as Yoast, handle the redirects inside the .htaccess file.

Give me that brain lol , i agree you win lol interesting cheers

Thanks guys, this was a lot easier than I thought! Already managed to redirect 1 domain :) Do I just use the code below over and over again for all domains or is it possible to add more domains within this code:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ http://example.net/$1 [L,R=301,NC]
 
You can put 1 .htaccess file in your root folder and it will apply to all requests that come in. I prefer putting them in each domain folder for organization's sake and if you kill off a domain, you don't have needless htaccess rules.
 
You can put 1 .htaccess file in your root folder and it will apply to all requests that come in. I prefer putting them in each domain folder for organization's sake and if you kill off a domain, you don't have needless htaccess rules.
I only have 1 .htaccess file and 1 root folder, but lots of domains pointing to that root folder. So should my .htaccess file look like this?

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example1.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example1.com [NC]
RewriteRule ^(.*)$ http://example.net/$1 [L,R=301,NC]

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example2.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example2.com [NC]
RewriteRule ^(.*)$ http://example.net/$1 [L,R=301,NC]

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example3.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example3.com [NC]
RewriteRule ^(.*)$ http://example.net/$1 [L,R=301,NC]

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example4.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example4.com [NC]
RewriteRule ^(.*)$ http://example.net/$1 [L,R=301,NC]

Or is it possible to add more domains within the code "RewriteCond %{HTTP_HOST} ^example1.com [NC,OR]" with something separating the domains?
 
Yeah, I think something like this should work:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example1.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example1.com [NC,OR]
RewriteCond %{HTTP_HOST} ^example2.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example2.com [NC,OR]
RewriteCond %{HTTP_HOST} ^example3.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example3.com [NC,OR]
RewriteCond %{HTTP_HOST} ^example4.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example4.com [NC]
RewriteRule ^(.*)$ http://example.net/$1 [L,R=301,NC]
 
Back
Top