1

I have 2 cpanels. Both have a domain and a server. Code files and database are same on both side. I am told point old domain to new domain.

I wrote below code in index file and all public files which are not password protected in old server.

<?php 
header("HTTP/1.1 301 Moved Permanently"); 
header("Location: http://www.New-Website.com"); 
?>

Everything works fine so far.

Issue details

I renamed index file in old server as it is not password protected and then tried to access the renamed file.

I got Access Forbidden error as the file was not found on old domain.

Can you please suggest if there is any way that old domain points to new domain even after I stop using the services in old cpanel?

Pankaj
  • 9,749
  • 32
  • 139
  • 283

1 Answers1

0

OPTION 1 using cPanel

cPanel has an interface called "Assign Domain" it has 4 steps

(note that your cPanel flavor could be different from this one according to your host, however the steps should be almost the same )

step 1 (Enter Domain):

Here cPanel will try to resolve the domain you enterted (olddomain.com) and detect it's current DNS server

enter image description here

step 2 (Verify Ownership):

Here you are going to verify your ownership of the (olddomain.com).

cPanel detected that olddomain.com is currently resolved by NS1.SMARTNAME.COM .

I use the DNS method to completely leave my old server, no traffic at all to old server. it's also handy if you registered your domain with a company like godaddy and your server and host is on another company.

enter image description here

step 3 (Choose Addon vs. Parked):

Here you are going to chose Parked domain for your case

enter image description here

step 4 (Choose Addon Directory and Sub-domain):

This step is available only for addon domains in which you chose the public_directory of the new adddomain and the subdomain

OPTION 2 using 1 frontController PHP file and rewrite rule(thanks for @tim in comments)

add a rewrite rule in your httpd.conf file that sends every request to your frontController PHP file

RewriteEngine On
RewriteCond "%{REQUEST_URI}" "!=/frontController.SE.php"
RewriteRule .* /frontController.SE.php [L]

and create a new PHP file called frontController.SE.php

<?php 
header("HTTP/1.1 301 Moved Permanently"); 
header("Location: http://www.New-Website.com");
exit; 
?>

that is better than coping the same code in all of your public files

Accountant م
  • 6,975
  • 3
  • 41
  • 61
  • Where can I search for httpd.config? – Pankaj Aug 21 '19 at 01:19
  • There is another issue. Let's say, the default file(index.php) is renamed or removed. Then it gives an error access forbidden because the file is not found. I tested this issue on other files also. Same issue occurs. – Pankaj Aug 21 '19 at 02:31
  • @Pankaj httpd.conf is the Apache configuration file, your webserver is Apache, right ? – Accountant م Aug 21 '19 at 02:52
  • @Pankaj Access forbidden is different from file not found, do you get 404 error in your browser when you request `index.php` ? – Accountant م Aug 21 '19 at 02:54
  • My server is shared hosting. There is no root access. So, where should I find the httpd.conf file? – Pankaj Aug 21 '19 at 02:58
  • Error 403. Error Details: You don't have permission to access the requested directory. There is either no index document or the directory is read-protected. If you think this is a server error, please contact the webmaster. – Pankaj Aug 21 '19 at 03:01
  • @Pankaj Ask your host if they allow you to modify the Apache configuration file(httpd.conf), if not then you should go to .htaccess files. check [this question](https://stackoverflow.com/questions/12202021/lost-httpd-conf-file-located-apache) for the location of `httpd.conf` file – Accountant م Aug 21 '19 at 03:02
  • This happens when I rename the index file to test the permanent redirect to make sure if it will still work after removing the file. I have to stop the services from old cpanel. So, this does not seems safe to stop using the services from old cpanel. The old cpanel does not allow to modify the httpd.conf as there is no root access. – Pankaj Aug 21 '19 at 03:04
  • @Pankaj Aha, now I understand your problem, you renamed `index.php` which is the default file to request if you requested the directory without specific file, for example , you request `mydomain/` , the webserver will try to find `index.php` or `index.html` in that directory, if it didn't find it, it will give this error that tells you you don't have the permission to the directory itself, you should keep your name as `index.php`, why do you want to change it ? – Accountant م Aug 21 '19 at 03:05
  • Actually, we have to stop using the services from old cpanel and we want to shut down the old cpanel completely. That's why I thought to test the permanent redirect by doing this. I was testing a case when the old panel i shut down. – Pankaj Aug 21 '19 at 03:07
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/198211/discussion-between-pankaj-and-accountant-). – Pankaj Aug 21 '19 at 03:07