Help me with this WordPress redirection

Bloodseeker

Elite Member
Jr. VIP
Joined
Apr 30, 2018
Messages
1,829
Reaction score
1,448
I want to redirect site example.com to lameexample.com entirely but below are conditions:

example.com/page1 should redirect to lameexample.com/page1

example.com/page2
should redirect to lameexample.com/page2

Then all the other pages (excluding above ones) including home of example.com should redirect to the domain lameexample.com

How do I do it?
 
how your domain nhttps://nodegenesis.com/dhg redirect to domainhuntergatherer.com ?
 
Code:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^https://example.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?google.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ – [NC,F,L]
RedirectMatch 301 ^/page1/?$ lameexample.com/page1
RedirectMatch 301 ^/page2/?$ lameexample.com/page2

I think it's something like this, I usually use plugins to redirect specific pages since its less effort. (Double-check this before you use it) Will redirect specific pages to specific pages and bulk redirect the rest to a single domain.
 
On top of what’s already been mentioned about the redirection plugin, here’s a video on using it:

 
Plugins, plugins everywhere!! :D

You don't need a plugin for this tbh. In your theme's functions.php, you could do things such as..

Code:
if($_SERVER['REQUEST_URI'] == "/some-awesome-page") {
header('Location: https://www.blackhatworld.com');
}

However, this is much more resource intensive at large scale (same goes for the plugin you might use, as well). I'd rather suggest doing it with apache (or nginx, if you are using nginx). That way, there does not have to be php execution atall. Other members already posted settings for the apache. If you are using nginx, something like the following would do the trick:

Code:
https://stackoverflow.com/a/47301913/1437261
 
how your domain nodegenesis.com redirect to domainhuntergatherer.com ?
Rebrandly

Not a fan of too many plugins, but this is the most simple path: Redirection plugin. 301 redirect all the links, according to your requirements.
Already using it on one of my sites, but I don't see it fulfilling my requirements.

Code:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^https://example.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?google.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ – [NC,F,L]
RedirectMatch 301 ^/page1/?$ lameexample.com/page1
RedirectMatch 301 ^/page2/?$ lameexample.com/page2

I think it's something like this, I usually use plugins to redirect specific pages since its less effort. (Double-check this before you use it) Will redirect specific pages to specific pages and bulk redirect the rest to a single domain.
Will give it a try, thanks man :)

Plugins, plugins everywhere!! :D

You don't need a plugin for this tbh. In your theme's functions.php, you could do things such as..

Code:
if($_SERVER['REQUEST_URI'] == "/some-awesome-page") {
header('Location: https://www.blackhatworld.com');
}

However, this is much more resource intensive at large scale (same goes for the plugin you might use, as well). I'd rather suggest doing it with apache (or nginx, if you are using nginx). That way, there does not have to be php execution atall. Other members already posted settings for the apache. If you are using nginx, something like the following would do the trick:

Code:
https://stackoverflow.com/a/47301913/1437261
I don't think it will work for my particular use case. Thanks though :)
 
Back
Top