Latest 301 or 302 Redirection Interview Questions
What is Redirection?
On a Web site, redirection is a technique for moving visitors to a different Web page OR Different Website.
Why we do Redirection?
We do Redirection, because we want to tell the visitor that current page is not appropriate for you.
Following are different reason, we do Redirection
If user already login, and try to open the login page redirect him to user dashboard.
Trying to access a page which is temporary not available.
If user trying to access un-authorized page, Redirect him to user dashboard.
Tring to access non-exist page, redirect him sitemap page OR 404 page.
Trying to access non-exist website.
What are different type of redirects?
301 permanent redirects
302 temporary redirects
What is 301 permanent redirects?
301 refers to the HTTP status code.
A 301 redirect is a permanent redirect which passes between ranking power(>90%) to the redirected page.
When we use 301 redirects?
When a web page permanently removed, we redirect user to new page.
When we want to transfer the ranking benefits(SEO point of view) to new web page.
Redirect user to new web page and stopped him to access old page(not available page).
If you have updated the contents to new web page, MUST USE 301 Redirects
301 indicates to both browsers and search engine bots(Google, bing, yahoo) that the page has moved permanently.
What is 302 temporary redirects?
302 refers to the HTTP status code.
A 302 redirect is a temporary redirect. We have to tell user its temporary unavailable and will be available very soon.
When we use 302 redirects?
If user already login, and try to open the login page redirect him to user dashboard.
Trying to access a page which is temporary not available.
If user trying to access un-authorized page, Redirect him to user dashboard.
How to make 301 redirect with php?
header(‘Location: http://www.example.com/new-web-page.php’, true, 301);exit;
How to make 302 redirect with php?
header(‘Location: http://www.example.com/new-web-page.php’, true, 302);exit;
OR
header(‘Location: http://www.example.com/new-web-page.php’);exit;
Both are same and works same.
Can we use regular express in Redirection?
Yes, See Example:
if(preg_match(“/^\/old\./”, $_SERVER[‘REQUEST_URI’], $m)){
header(‘Location: http://www.example.com/new-web-page.php’, true, 301);exit;
}
URL start with /old will be redirect to http://www.example.com/new-web-page.php
Give an URL to check 301 redirects?
http://www.aboutcity.net/youtube/videos/watch/wEVPkxFC0NI
Where can I test redirect online? http://www.redirect-checker.org/index.php
(Check Your Redirects and Statuscode 301 vs 302, meta refresh & javascript redirects)
How to make 301 redirect with htaccess?
Add following code in htaccess
Redirect 301 /old/ /new/
Make Sure “RewriteEngine On” and installed “mod_rewrite” on server.
How to make 302 redirect with htaccess?
Add following code in htaccess
Redirect 302 /old/ /new/
Make Sure “RewriteEngine On” and installed “mod_rewrite” on server.
What are different HTTP status code used in web?
301 – Permanent movement(redirection)
302 – Temporary movement(redirection)
400 – Bad request
401 – Authorization Required