We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 33982 ☆ A M B ☆
    • 476 Posts
    So I’ve got a client that has a MODx website that is up and running. He now has decided to switch the domain name to a new domain name. The current website has 521 documents. I’m going to transfer the entire site over to the new domain name, but how do we redirect each page from the current site to the corresponding site?

    For example:

    www.abc123.com/contact-us.html

    redirect to:

    www.xyz456.com/contact-us.html

    All the document aliases will stay the same, just the site URL will change.

    Is there a simple script or would it require writing out all the documents in the .htaccess file to redirect (which would take forever) to the new URL for each document?
      Precision Web Development ... SmashStack.com
      • 4310
      • 2,310 Posts
      In your .htaccess file on the old domain have something like :
      RewriteEngine On
      RewriteBase /
      RewriteCond %{HTTP_HOST} .
      RewriteCond %{HTTP_HOST} !^www\.old-domain\.com [NC]
      RewriteRule (.*) http://www.new-domain.com/$1 [R=301,L]
      RewriteCond %{HTTP_HOST} !^old-domain\.com [NC]
      RewriteRule (.*) http://www.new-domaincom/$1 [R=301,L]]

      That should redirect anything going to either http://old-domain.com/somepage.html or http://www.old-domain.com/somepage.html
      to http://www.new-domain.com/somepage.html.
      If you’re not duplicating the site exactly, then you’d need some custom re-write rules.
      You’d need to place custom rules just after RewriteBase / to ensure they were processed before the catch all redirect.
        • 33982 ☆ A M B ☆
        • 476 Posts
        Good deal...thanks so much...I’ll give it a spin.
          Precision Web Development ... SmashStack.com
          • 33982 ☆ A M B ☆
          • 476 Posts
          Hey bunk58,

          I successfully made the change. I modified the code here in the .htaccess file:
          # Rewrite www.domain.com -> domain.com -- used with SEO Strict URLs plugin
          #RewriteCond %{HTTP_HOST} .
          #RewriteCond %{HTTP_HOST} !^example-domain-please-change\.com [NC]
          #RewriteRule (.*) http://example-domain-please-change.com/$1 [R=301,L]
          #
          # or for the opposite domain.com -> www.domain.com use the following
          # >>> DO NOT USE BOTH THE ABOVE AND BELOW <<<
          #
          RewriteCond %{HTTP_HOST} .
          RewriteCond %{HTTP_HOST} !^www\.old-domain\.com [NC]
          RewriteRule (.*) http://www.new-domain.com/$1 [R=301,L]
          RewriteCond %{HTTP_HOST} !^old-domain\.com [NC]
          RewriteRule (.*) http://www.new-domain.com/$1 [R=301,L]
          


          Thanks for your help!
            Precision Web Development ... SmashStack.com