Psychz - Bruce
Votes: 0Posted On: Nov 05, 2020 11:25:20
Redirects are highly useful when you migrate a website or move a page to a new URL by ensuring that user finds appropriate destination.
Using .htaccess
You can use .htaccess if you are running apache server. You can create a file named .htaccess in any of the directory to locally override server configurations. The .htacccess file usually exist in the root directory of the website. Using a simple syntax inside this file can help you setup page, directory, or site redirects.
Let's see how you can redirect an entire website
Using the above syntax, the redirect assumes that everything on the new site is in the same place as it was on the old site:
Using JavaScript
If you would like to use JavaScript to redirect to a new URL or page please follow the method given below
Note: If you are planning to move your website to a separate domain, it’s better to use the server redirection because redirection using JavaScript runs entirely on the client-side and hence it does not return the status code 301 (move permanently) like server redirection.
To redirect to a new URL from the current page, you can use the location object:
location.href = 'new_url';
example:
You can also use
location.assign('https://www.newsite.com/');
Hope you find the information above useful. Please hit the like button below to show your appreciation.