0

The issue at hand is redirecting selected pages from the olddomain to the newdomain1 and newdomain2. Doing one domain is fairly straightforward, but it's different when handling two domains.

Any assistance at all would be greatly appreciated!

 

FILE: .htaccess (Old Domain Name's cPanel)

Code to allow redirects for two domain names. NOTE: This is the first line of code in the file

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ https://newdomain1.example/ [L,R=301]
RewriteRule ^(.*)$ https://newdomain2.example/ [L,R=301]

FILE: .htaccess (Old Domain Name's cPanel)

Redirects old domain olddomain to new domain newdomain1 (forcing pages that don't have redirects to load 404s on domain1)

RedirectMatch 301 ^/$ https://newdomain1.example/ 

Problem to solve

Redirects listed below are not working. This code is added underneath the RedirectMatch 301.

FILE: .htaccess (Old Domain Name's cPanel)

Redirect 301 /team/ https://newdomain1.example/about/our-team/ Redirect 301 /about/ https://newdomain2.example/about-us/

Attempted code to resolve issue, but didn't work:

# Redirect olddomain.example/oldpage1 to newdomain1.example/newpage1
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.example$ [NC]
RewriteRule ^oldpage1$ http://newdomain1.example/newpage1 [L,R=301]

# Redirect olddomain.example/oldpage2 to newdomain2.example/newpage2
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.example$ [NC]
RewriteRule ^oldpage2$ http://newdomain2.example/newpage2 [L,R=301]

Edit: May 29, 2023 - Top of file

Tasks at hand:

  1. Redirect the homepage of oldwebsite to newwebsite1.

  2. Redirect pages that don't exist on of oldwebsite to newwebsite1 so they 404 and not load the oldwebsite.

  3. Redirect pages from oldwebsite to newwebsite1.

  4. Redirect pages from oldwebsite to newwebsite2.

The oldwebsite has been split into two different websites, and content was moved to two domains instead one which is more typical.

  1. From the below code, tried commenting out both RewriteCond %{REQUEST_FILENAME} !-f and RewriteCond %{REQUEST_FILENAME} !-d to see if this would resolve the issue of redirecting all links to the homepage. Single redirects are meant to redirect to specific pages.
     # BEGIN 301 Redirects - Old Domain to New Domain
     # Website Name
     RewriteEngine On
     RewriteCond %{REQUEST_FILENAME} !-f
     RewriteCond %{REQUEST_FILENAME} !-d
     RewriteRule ^(.*)$ https://newwebsite1.example/ [L,R=301]
     # END 301 Redirects - Old Domain to New Domains
  1. The code below is meant to ensure the oldwebsite's homepage redirects to newwebsite1's homepage.
     # BEGIN 301 Redirects 
     # Website Name
     # 301 Redirects - New Website - Homepage Only
     RedirectMatch 301 ^/$ https://newwebsite1.example/ 
  1. From the below code, we're wanting one page from oldwebsite to redirect to one page on newwebsite1. There are over 100 redirects for newwebsite1.

Redirect 301 /about/ https://newwebsite1.example/about/

  1. From the below code, we're wanting one page from oldwebsite to redirect to one page on newwebsite2. There are over 100 redirects for newwebsite2.

Redirect 301 /team/ https://newwebsite2.example/our-team/

Edit: May 30, 2023 - This code is listed at the bottom:

# BEGIN cPanel-generated php ini directives, do not edit
# Manual editing of this file may result in unexpected behavior.
# To make changes to this file, use the cPanel MultiPHP INI Editor (Home >> Software >> MultiPHP INI Editor)
# For more information, read our documentation (https://go.cpanel.net/EA4ModifyINI)
<IfModule php7_module>
   php_flag display_errors Off
   php_value max_execution_time 300
   php_value max_input_time 300
   php_value max_input_vars 4000
   php_value memory_limit 256M
   php_value post_max_size 1024M
   php_value session.gc_maxlifetime 1440
   php_value session.save_path "/var/cpanel/php/sessions/ea-php74"
   php_value upload_max_filesize 1024M
   php_flag zlib.output_compression Off
</IfModule>
<IfModule lsapi_module>
   php_flag display_errors Off
   php_value max_execution_time 300
   php_value max_input_time 300
   php_value max_input_vars 4000
   php_value memory_limit 256M
   php_value post_max_size 1024M
   php_value session.gc_maxlifetime 1440
   php_value session.save_path "/var/cpanel/php/sessions/ea-php74"
   php_value upload_max_filesize 1024M
   php_flag zlib.output_compression Off
</IfModule>
# END cPanel-generated php ini directives, do not edit

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php74” package as the default “PHP” programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php74 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit

This concludes everything from the file has been added.

Status: Only the oldwebsite and oldwebsite's pages are redirecting to newwebsite1's homepage.

26
  • Do these domains point to the same place or different servers/vHosts? So, what are you wanting to redirect and to where? The first code block is a bit odd (but it depends what you are trying to do). The second and third code blocks are OK, but you should avoid mixing mod_alias and mod-rewrite (the first and last code blocks). The last code block is OK (although the Host check is redundant if the olddomain points to a different server) and the order of directives is important. Please include your complete .htaccess file and the URLs you want to redirect.
    – MrWhite
    May 25, 2023 at 21:32
  • 1
    Do you have any files still residing at olddomain (if it is pointing to a different server)? Btw, the "description" of the rule you have written before the rule does not seem to describe what it does?
    – MrWhite
    May 25, 2023 at 21:32
  • Your question is unclear. You appear to have 2 different contents for the single .htaccess which is impossible - what are the paths for each .htaccess? Where did you add the redirect Match?
    – davidgo
    May 26, 2023 at 3:38
  • 1
    "olddomain, newdomain1 and newdomain2 are all on the same shared hosting" - and all are pointing to the same directory on the filesystem (including newdomain1 and newdomain2)?! (If the olddomain points to the same place then the first two code blocks really make no sense?) As per my first comment, "Please include your complete .htaccess file and the URLs you want to redirect from/to" - without this information we cannot answer this question, since there is nothing particularly wrong with the last two code blocks (except, as stated, you should not mix redirects from both modules).
    – MrWhite
    May 26, 2023 at 22:00
  • 1
    @StephenOstermiller The domains have their own cPanel accounts on the same server. The .htaccess file listed above is for oldwebsite. May 30, 2023 at 20:59

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.