LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Creating 301 Permanent Redirect to a domain with same docroot as old domain. (https://www.linuxquestions.org/questions/linux-newbie-8/creating-301-permanent-redirect-to-a-domain-with-same-docroot-as-old-domain-4175461485/)

MarkToronto 05-10-2013 08:06 PM

Creating 301 Permanent Redirect to a domain with same docroot as old domain.
 
Hello, this is my first post here. I did search the forums trying to find an answer, but nothing seemed to allay my fears of what I am about to do.

I am attempting to rebrand my sister's website to a new brand new domain name. But there is only the one docroot with all the pages. I want to create 301 redirects for each page to the new domain, but the problem is that I think if I change the .htaccess file in the docroot to redirect
(say /home/index.php to
https://www.newdomain.com/home/index.php )
then that would send the site into weird a loop since it would just point back at the same docroot.

So.... My thought is that I need to create a brand new docroot folder with an .htaccess file containing all of my 301 redirects to the pages on the new domain. I will point the old website domain at that new docroot, and I will point the new domain at the old docroot.

Does that sound like the right approach?

All of the directory structure and pages under the docroot are the same as the old site. The site in question is an OpenCart site (PHP pages with parameters on the URLs).

So URLs are either like
https://www.olddomain.com/CategoryName
or
https://www.olddomain.com/index.php?route=account/login

My ultimate goal is to tell all search engines that the domain has changed permanently, and to also redirect the customers to the new store (hopefully to the same page they were trying to hit from Google). And hopefully not loose all the search engine stats accumulated by Google.

Is the RedirectPermanent the best directive for this?

Thanks for any help you can give,
Mark

TenTenths 05-15-2013 03:35 AM

If your files/folder structure is going to remain identical then set your site up so that the new domain works, then add the following to your apache config either in the conf file for the new domain or as a separate vHost:

Code:

<VirtualHost your.server.ip.here:80>
  ServerName www.olddomain.com
  ServerAlias olddomain.com
  RedirectMatch 301 (.*) http://www.newdomain.com$1
</VirtualHost>



All times are GMT -5. The time now is 06:07 AM.