Redirect in cpanel with several wordpress sites

KimberH

Active Member
Dec 29, 2013
40
6
58
cPanel Access Level
Website Owner
Hi, I have four wordpress on one domain name. I'm moving one to another domain name.

Example
mydomain.com/ wordpress site would redirect to a new domain name.
mydomain.com/folder1 wordpress site would not forward
mdomain.com/folder2 wordpress site would not forward
mydomain.com/folder3 wordpress site would not forward

Mydomain.com is in maintenance mode and will deleted soon. Are there tools in cpanel that could help me do this type of redirect?

Thank you for your time
Kim
 
Last edited by a moderator:

rbairwell

Well-Known Member
May 28, 2022
98
42
18
Mansfield, Nottingham, UK
cPanel Access Level
Root Administrator
You'll want a .htaccess rule in Apache to setup these rewrites.

I think this should do the job:
Code:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/folder(1|2|3)/  [NC]
RewriteRule ^(.*)$ https://www.example.net/$1 [R=301,L,NC]
(tested on htaccess.madewithlove.com )

In order:
1. RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC] indicates to match the hostname to www.example.com only (NC=not case sensitive)
2. RewriteCond %{REQUEST_URI} !^/folder(1|2|3)/ [NC] says if the Request URL does NOT (the exclamation mark) start with (the caret ^ character) the text "folder1" or "folder2" or "folder3" (folder(1|2|3) is an expression meaning any of those numbers could follow the word folder) followed by a forward slash , then continue.
3. RewriteRule ^(.*)$ https://www.example.net$1 [R=301,L,NC] redirect the full url (^(.*)$) to https://www.example.net followed by the captured url ($1) using a 301 Permanent redirect message, not case sensitive and make this the Last rule in the set.

Alternatively, there's:
Code:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/folder1/  [NC,L]
RewriteCond %{REQUEST_URI} !^/folder2/  [NC,L]
RewriteCond %{REQUEST_URI} !^/folder3/  [NC,L]
RewriteRule ^(.*)$ https://www.example.net/$1 [R=301,L,NC]
Which goes:
1. RewriteCond %{REQUEST_URI} !^/folder1/ [NC,L] : if the URL does NOT start with folder1 (not case sensitive), then make this this Last part of this rewrite match.
2,3 4: I'll leave you to work out those bits yourself :)
5: RewriteRule ^(.*)$ https://www.example.net/$1 [R=301,L,NC] if none of the previous rules have caused a match, then redirect.

(tested on htaccess.madewithlove.com )

You might find Apache's Rewrite manual page a useful reference.
 
  • Like
Reactions: cPRex