url redirection read
TRANSCRIPT
-
7/28/2019 Url Redirection Read
1/37
with Apache web serverwith Apache web server
Informational Success Redirection Client error Server error
xx xx xx xx xx
-
7/28/2019 Url Redirection Read
2/37
Topics1 2
LEARN ABOUT HTTP STATUS CODE
1
1xx Informational 2xx Success
3xx Redirection 4xx Client error 5xx Server error
HOW TO REDIRECT YOUR URL Main reason for redirect URL Pre arin stuff
2
Where we place the rule Rewrite rule Example 1 : non-www to www redirection
Example 3 : sub domain redirection
-
7/28/2019 Url Redirection Read
3/37
Http status codet s response status co e w c s part o t e 1.1 stan ar .
xx
Informational Server is performingsome further actionand does not yet have adefinitive response
Client error
xxError was found fromclient side
xxSuccess
The action requested bythe client wassuccessful received
Server error
xx
The server failed tofulfill a valid request
xx3
Redirection
Site will be redirectedor URL forwarding
-
7/28/2019 Url Redirection Read
4/37
Topics
LEARN ABOUT HTTP STATUS CODE
1
1xx Informational 2xx Success
3xx Redirection 4xx Client error 5xx Server error
HOW TO REDIRECT YOUR URL Main reason for redirect URL Pre arin stuff
2
Where we place the rule Rewrite rule Example 1 : non-www to www redirection
Example 3 : sub domain redirection
-
7/28/2019 Url Redirection Read
5/37
Informational Server is performingsome further actionand does not yet have a
1 2
definitive response
a us co e escr p on
100
continue
Allow a client that is sending a request message to determine if server is willing to accept the
request.
101SwitchingProtocols
Server will switch protocols to those defined by the response's Upgrade header field immediatelyafter the empty line which terminates the 101 response.
-
7/28/2019 Url Redirection Read
6/37
Topics
LEARN ABOUT HTTP STATUS CODE
1
1xx Informational 2xx Success
3xx Redirection 4xx Client error 5xx Server error
HOW TO REDIRECT YOUR URL Main reason for redirect URL Pre arin stuff
2
Where we place the rule Rewrite rule Example 1 : non-www to www redirection
Example 3 : sub domain redirection
-
7/28/2019 Url Redirection Read
7/37
SuccessThe action requested bythe client was
1 2
a us co e escr p on
201
created
New resource being created.
202accepted
The request has been accepted for processing.
non-authoritativeinformation
The returned metainformation in the entity-header is not the definitive set as available from theorigin server.
204no content
The server has fulfilled the request but does not need to return an entity-body, and might want toreturn updated metainformation.
205 The server has fulfilled the request and the user agent should reset the document view whichreset content caused the request to be sent.
206partial content
The server has fulfilled the partial GET request for the resource.
-
7/28/2019 Url Redirection Read
8/37
Topics
LEARN ABOUT HTTP STATUS CODE
1
1xx Informational 2xx Success
3xx Redirection 4xx Client error 5xx Server error
HOW TO REDIRECT YOUR URL Main reason for redirect URL Pre arin stuff
2
Where we place the rule Rewrite rule Example 1 : non-www to www redirection
Example 3 : sub domain redirection
-
7/28/2019 Url Redirection Read
9/37
Redirection
Site will be redirectedor URL forwarding
1 2
a us co e escr p on
300
Multiple Choices
The requested resource correspond to multiple specific location.
301Moved
PermanentlyThe requested resource has been assigned to new permanent URI.
302
Found
The requested resource resides temporarily under a different URI. This response is only cacheable
if indicated by a Cache-Control or Expires header field.
303 The response to the request can be found under a different URI and SHOULD be retrieved using aee er me o on a resource.
304Not Modified
If the client has performed a conditional GET request and access is allowed, but the document hasnot been modified.
305Use Proxy
The requested resource must be accessed through the proxy given by the location field.
-
7/28/2019 Url Redirection Read
10/37
1 2
306(Unused)
The 306 status code was used in a previous version of the specification, is no longer used, and thecode is reserved.
307Temporary
Redirect
If the 307 status code is received in response to a request other than GET or HEAD, the user agentmust not automatically redirect the request unless it can be confirmed by the user, since this mightchange the conditions under which the request was issued.
-
7/28/2019 Url Redirection Read
11/37
Topics
LEARN ABOUT HTTP STATUS CODE
1
1xx Informational 2xx Success
3xx Redirection 4xx Client error 5xx Server error
HOW TO REDIRECT YOUR URL Main reason for redirect URL Pre arin stuff
2
Where we place the rule Rewrite rule Example 1 : non-www to www redirection
Example 3 : sub domain redirection
-
7/28/2019 Url Redirection Read
12/37
Client error
Error was found fromclient side
1 2
a us co e escr p on
400
Bad Request
The requested cannot be fulfilled due to bad syntax.
401Unauthorized
It will happen when authentication has failed.
402
PaymentRequired
Reserve for future use for digital cash or micro payment.
403Forbidden
e reques was a ega reques , u e server s re us ng o respon o .
404Not Found
Therequested resourcecouldnotbefoundbutmaybeavailableagaininthefuture.
405Method Not
Allowed
Arequestwas madeofaresourceusingarequestmethodnotsupportedbythatresource.Forexample,usingGETonaformwhichrequiresdatatobepresentedviaPOST.
-
7/28/2019 Url Redirection Read
13/37
Status code Description
1 2
406Not Acceptable
The requested resource is only capable of generating content not acceptable according to theAccept headers sent in the request.
407Proxy
AuthenticationRequired
It need proxy authentication for accessing the site.
408Request Timeout
The server timed out waiting for the request.
409Conflict
.
410Gone
Indicates that the resource requested is no longer available and will not be available again.
411
Length RequiredThe request did not specify the length of its content.
412Precondition
FailedThe server does not meet one of the preconditions that the requester put on the request.
413
Request EntityToo Large
The request is larger than the server is willing or able to process.
-
7/28/2019 Url Redirection Read
14/37
Status code Description
1 2
414Request-URI
Too LongThe URI provided was too long for the server to process.
415UnsupportedMedia Type
The request entity has a media type which the server or resource does not support.
Requested Range
Not SatisfiableThe client has asked for a portion of the file, but the server cannot supply that portion.
417xpec a on
Failed
e server canno mee e requ remen s o e xpec reques - ea er e .
418I'm a teapot
This request is not expected to be implemented by actual HTTP servers.
-
7/28/2019 Url Redirection Read
15/37
Topics
LEARN ABOUT HTTP STATUS CODE
1
1xx Informational 2xx Success
3xx Redirection 4xx Client error 5xx Server error
HOW TO REDIRECT YOUR URL Main reason for redirect URL Pre arin stuff
2
Where we place the rule Rewrite rule Example 1 : non-www to www redirection
Example 3 : sub domain redirection
1 2
-
7/28/2019 Url Redirection Read
16/37
Server error
The server failed tofulfill a valid request
1 2
a us co e escr p on
500Internal Server
Error
A generic error message, given when no more specific message is suitable.
501Not
ImplementedThe server either does not recognize the request method, or it lacks the ability to fulfill the request.
502Bad Gateway
The server was acting as a gateway or proxy and received an invalid response from the upstreamserver.
503erv ce
Unavailablee server s curren y unava a e ecause s over oa e or own or ma n enance .
504Gateway The server was acting as a gateway or proxy and did not receive a timely response from theupstream server.
505HTTP VersionNot Supported
The server does not support the HTTP protocol version used in the request.
1 2
-
7/28/2019 Url Redirection Read
17/37
Status code Descri tion
1 2
506Variant AlsoNegotiates
Transparent content negotiation for the request results in a circular reference.
507Insufficient
StorageDisk is running out of space.
Bandwidth LimitExceeded
This status code, while used by many servers, is not specified in any RFCs.
Not Extended
Further extensions to the request are required for the server to fulfill it.
-
7/28/2019 Url Redirection Read
18/37
Topics
LEARN ABOUT HTTP STATUS CODE
1
1xx Informational 2xx Success
3xx Redirection 4xx Client error 5xx Server error
HOW TO REDIRECT YOUR URL Main reason for redirect URL Pre arin stuff
2
Where we place the rule Rewrite rule Example 1 : non-www to www redirection
Example 3 : sub domain redirection
1 2
-
7/28/2019 Url Redirection Read
19/37
Main reason for redirect URL1 2
1. SecurityHide underl in technolo index. h
Hide actual path of files http://www.xxx.com/images/simple?photo=34
2. Good for peopleEasy to remember http://www.xxx.com
3. Good for search engineSearch engine like friendly URL http://www.xxx.com/contact
-
7/28/2019 Url Redirection Read
20/37
Topics
LEARN ABOUT HTTP STATUS CODE
1
1xx Informational 2xx Success
3xx Redirection 4xx Client error 5xx Server error
HOW TO REDIRECT YOUR URL Main reason for redirect URL Pre arin stuff
2
Where we place the rule Rewrite rule Example 1 : non-www to www redirection
Example 3 : sub domain redirection
1 2
-
7/28/2019 Url Redirection Read
21/37
Preparing stuff1 2
Install Apache on your web server and enable mod_rewrite engine
ewr e ng ne n
-
7/28/2019 Url Redirection Read
22/37
Topics
LEARN ABOUT HTTP STATUS CODE
1
1xx Informational 2xx Success
3xx Redirection 4xx Client error 5xx Server error
HOW TO REDIRECT YOUR URL Main reason for redirect URL Pre arin stuff
2
Where we place the rule Rewrite rule Example 1 : non-www to www redirection
Example 3 : sub domain redirection
h l h l1 2
-
7/28/2019 Url Redirection Read
23/37
Where we place the rule
Apache config file - httpd.conf
Htaccess file - .htaccess
T i
-
7/28/2019 Url Redirection Read
24/37
Topics
LEARN ABOUT HTTP STATUS CODE
1
1xx Informational 2xx Success
3xx Redirection 4xx Client error 5xx Server error
HOW TO REDIRECT YOUR URL Main reason for redirect URL Pre arin stuff
2
Where we place the rule Rewrite rule Example 1 : non-www to www redirection
Example 3 : sub domain redirection
R it l1 2
-
7/28/2019 Url Redirection Read
25/37
Rewrite rule
To be more understanding for rewrite rule, Its good to familiar with the syntax and
pattern of rewrite rule.
RewriteRule ^somefile-([0-9]+)\.htm$ /dir/index.php?id=$1 [L]
Pattern Target Flag
P1 2
-
7/28/2019 Url Redirection Read
26/37
Pattern
Pattern has been used for matches the URL path and Regular expression has been used
to detect the requested URI.
Char Definition
*. .
^ Start matching at this point.
$ End point of the match.
. Any character.
[] Starts a class.
Starts alternative match this that would mean match this or that.
() Starts a back reference point.
? Match 0 or 1 time Quantifier.
+ Match atleast 1 or more times Quantifier.
* Match 0 to infinite times Quantifier.
{} Match minimum to maximum Quantifier {0,3} match up to 3 times.
Cl []1 2
-
7/28/2019 Url Redirection Read
27/37
Class []
Char Definition
^ Negates the class. [^A-Z]+ means don't match any uppercases.
Use before an of the followin characters to esca e or null the meanin or it. [ +]+.
- Range for matching [0-9]+ [a-zA-Z]+.
T t1 2
-
7/28/2019 Url Redirection Read
28/37
TargetIt can e use or rep acing any matc e URL.
File-system path
URL pathcould be used
Absolute URL as a target.
- [dash] (no substitution)
Flag1 2
-
7/28/2019 Url Redirection Read
29/37
Flag
Char Definition
Flag can modify the behavior of a Rewrite rule.
[R] Redirect you can add an =301 or =302 to change the type.
[F] Forces the URL to be forbidden. 403 header.
[G] Forces the URL to be gone 401 header.
[L] Last rule. (You should use this on all your rules that don't link together)
[N] Next round. Rerun the rules again from the start.
.
[T] Use T = MIME-type to force the file to be a mime type.
[NS] Use if no sub request is requested.
[NC] Makes the rule case Insensitive.
[QSA] Query String Append use to add to an existing query string.
.
[PT] Pass through to the handler. (together with mod alias)
[S] Skip the next rule S=3 skips the next 3 rules.
[E] E = sets an environmental variable that can be called by other rules.
[P] E = rules are served through a proxy subrequest.
Topics
-
7/28/2019 Url Redirection Read
30/37
Topics
LEARN ABOUT HTTP STATUS CODE
1
1xx Informational 2xx Success
3xx Redirection 4xx Client error 5xx Server error
HOW TO REDIRECT YOUR URL Main reason for redirect URL Pre arin stuff
2
Where we place the rule Rewrite rule
Example 1 : non-www to www redirection
Example 3 : sub domain redirection
Example 1 : non www to www redirection1 2
-
7/28/2019 Url Redirection Read
31/37
Example 1 : non-www to www redirectionhttp://xxx.com => redirect to http://www.xxx.com
RewriteEngine On
Match this URL http: xxx.com
RewriteCond %{HTTP_HOST} xxx\.com
The pattern captured
inside the parentheses
RewriteRule ^(.*)$ http://www.xxx.com/$1 [R=301,L]
capture as variable $1
make this as the last
Rewrite rule.
Topics
-
7/28/2019 Url Redirection Read
32/37
Topics
LEARN ABOUT HTTP STATUS CODE
1
1xx Informational 2xx Success
3xx Redirection 4xx Client error 5xx Server error
HOW TO REDIRECT YOUR URL Main reason for redirect URL Pre arin stuff
2
Where we place the rule Rewrite rule
Example 1 : non-www to www redirection
Example 3 : sub domain redirection
Example 2 : normal redirection1 2
-
7/28/2019 Url Redirection Read
33/37
Example 2 : normal redirectionhttp://xxx.com => redirect to http://yyy.com/about
RewriteEngine On
Match this URL http: xxx.com
RewriteCond %{HTTP_HOST} xxx\.com
RewriteRule ^/(.*)$ http://yyy.com/about [R=301,QSA,L]
capture as variable $1 but it is
not used for this case
,
query append string
and make this as the
last rewrite rule.
Topics
-
7/28/2019 Url Redirection Read
34/37
Topics
LEARN ABOUT HTTP STATUS CODE
1
1xx Informational 2xx Success
3xx Redirection 4xx Client error 5xx Server error
HOW TO REDIRECT YOUR URL Main reason for redirect URL Pre arin stuff
2
Where we place the rule Rewrite rule
Example 1 : non-www to www redirection
Example 3 : sub domain redirection
Example 3 : sub domain redirection1 2
-
7/28/2019 Url Redirection Read
35/37
Example 3 : sub domain redirectionhttp://xxx.com/blog/ => redirect to http://blog.xxx.com/
RewriteEngine On
RewriteRule ^/blog/?(.*)$ http://blog.xxx.com/$1 [P,NC,L]
atc og pattern ep ace wit t is u es are serve
through proxy, case
insensitive and make
rule.
References
-
7/28/2019 Url Redirection Read
36/37
References
http://www.webforgers.net/mod-rewrite/mod-rewrite-syntax.php
http://httpd.apache.org/docs/1.3/mod/mod_rewrite.htmlhttp://www.w3.org/Protocols/rfc2616/rfc2616-sec10.htmlhttp://en.wikipedia.org/wiki/List_of_HTTP_status_codeshttp://en.wikipedia.org/wiki/URL_redirection#Manual_redirect
-
7/28/2019 Url Redirection Read
37/37