301 redirect via index.php in server root not redirecting properly - http-status-code-301

I am having issues with a 301 redirect.
I just purchased new shared web hosting. I then set the nameservers (of the domain I wish to redirect) to the new webhost nameservers.
I then uploaded index.php into public_html via cPanel.
Inside index.php I have the following code:
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: en.wikipedia.org/wiki/my_company_page");
?>
I then went to the domain and it did not redirect properly in a web browser.
Instead of being redirect to:
en.wikipedia.org/wiki/my_company_page
I was redirected to:
http://www.OriginalDomain.com/en.wikipedia.org/wiki/my_company_page
I have done this several times over the past few years....I looked at another website I have (same shared hosting company, same method of 301 redirecting) and it's working perfectly.
Can you guys/gals figure out why it's not working this time?
Could it be due to DNS not propagating (yet) as I just switched over the nameservers.

WHat about header("Location: http://en.wikipedia.org/wiki/my_company_page");?

I don't have any files in the server. I just want to redirect via index.php. I have done this many times before....but I cannot figure out why this time it is not working.
I'm suspecting it's due to the DNS still propagating....but was hoping someone could confirm that.

Related

Need help redirecting one website URL to another with apache2 and .htaccess

I have two domains - https://hosting.opensimcity.org, and http://paradigm.pocketmud.com and I want to redirect the latter to the former. That is, when someone connects to http://paradigm.pocketmud.com I want it to redirect to https://hosting.opensimcity.org/paradigm
Any tips on doing this in my .htaccess file?
Just try the following htaccess redirect code:
Redirect 301 / https://hosting.opensimcity.org/paradigm
This 301 redirect response notifies the search engines that the page has moved permanently from the old URL to the new URL. The search engines also transfer the old URL page rank to the new URL.

htaccess redirect specific pages to another domain

I’m having some real problems with 301 redirects in my .htaccess file.
I have about 20 pages on an old site that I need to redirect to pages on a new site. The URL structure of the new site is totally different.
Here’s one that I tried:
Redirect 301 /dan-carr-gear-list/travel-gear https://dancarrphotography.com/gear/travel/
Unfortunately, this doesn’t work.
What happens is that you get redirected to https://dancarrphotography.com/gear/travel-gear/ for some reason.
I just can’t figure it out.

Redirect sub domain and all its files old or new to new url

I have been searching for this, not sure if it can be done.
I want to redirect a subdomain and all its files old or new to the root domian
I did a basic redirect and the subdomain redirects to the domain just fine.
Problems is if a specific file is added to the subdomain ie. http://sub.maindomain. com/help.htm is brings up a 404 Page not found
Thanks for your help.
Dave

Redirect domain to subfolder with some specific pages fallback

I need to change website domain from www.domain.com to www.newdomain.com/en but I also need to specify some pages from old website to new website like www.domain.com/page to www.newdomain.com/en/subfolder/subfolder/page.
Last thing should be great keeping one subfolder path of old website free of redirect like www.domain.com/admin in order to keep backend access to old website.
What would you suggest me to add to old site htaccess file in order to achieve that with a sort of fallback mechanism for specifc pages and whole domain to subdirectory?
Thank you
You can add the following 301 redirect to your oldsite/htaccess :
Redirect 301 / http://newdomain.com/en/subfolder/subfolder/
This will redirect all requests from your old site to the subfolder in your new site
Edit : as per your comment,
to exclude a specific path from the redirection, you may use RedirectMatch
RedirectMatch 301 ^/((?!page1|page2).*) http://newdomain.com/en/subfolder/subfolder/$1
This will not redirect /page1 or /page2 .

domain name with or without 'www'

I have a domain e.g. named www.example.com, when people type in example.com, it still can be accessed, but won't automatically add that 'www' to the url.
But as for website like facebook, if you type in facebook.com, it'll automatically add that 'www', BEFORE loading the page for you.
Probably I didn't explain it well, but guess you see the difference and get my point anyway.
So how can I make my domain acts like facebook, when people type example.com, it'll automatically add that www for them?
EDIT:
Ok, so I need a redirect to the 'www' subdomain. Actually I'm using nodejs, which hosted on Amazon EC2, to serve the webpage instead of Apache HTTP. So any equivalent of .htaccess in nodejs area?
I guess now the question shifts to more nodejs oriented, and it turns out it becomes a redundant of this thread:
Redirect all requests using Express 3?
Thanks all for your help.
you have to set your domain 301 permanent redirect in your control panel.
if your website is hosted in CPANEL then
GOTO -> Redirects in ( Domains Menu )
Choose the type Permanent (301)
choose your domain.com
www.domain.com in redirects to→ __
check the box on Redirect with or without www
finally CLick ADD
if your website is hosted in PLESK then
do it in your program level
or
plesk11.0.29 version above supports the 301 peramanent
You can do all of this with a .htaccess file.
https://kb.mediatemple.net/questions/242/How+do+I+redirect+my+site+using+a+.htaccess+file%3F
# This allows you to redirect your entire website to any other domain
Redirect 301 / http://mt-example.com/
Add this in a file named .htaccess on your host, but set it to the URL you want your main page to be.
To make a .htaccess file, you can always go in FTP, upload an empty .txt file, open it with notepad, put in the lines of code above, then rename it to .htaccess.

Resources