SlideShare a Scribd company logo
1 of 37
Download to read offline
How to redirect URL
                                         with Apache web server




1 xx 2 xx 3 xx 4 xx 5 xx
 Informational   Success   Redirection       Client error   Server error
1   2
Topics

1   LEARN ABOUT HTTP STATUS CODE
       Http status code
       1xx Informational
       2xx Success
       3xx Redirection
       4xx Client error
       5xx Server error


2   HOW TO REDIRECT YOUR URL
    •   Main reason for redirect URL
    •   Preparing stuff
           p    g
    •   Where we place the rule
    •   Rewrite rule
    •   Example 1 : non-www to www redirection
    •   Example 2 : normal redirection
    •   Example 3 : sub domain redirection
Http status code
It i response status code which i part of th HTTP/ standard.
   is          t t     d hi h is     t f the HTTP/1.1 t d d




 1 xx
          Informational
            f         l   Server i performing
                                  is    f   i
                          some further action
                          and does not yet have a




                                                               4 xx
                          definitive response
                                                                 Client error
                                                                                Error was found from
                                                                                client side




 2 xx
               Success
                          The action requested by
                          the client was




                                                               5 xx
                          successful received
                                                                Server error
                                                                                The server failed to
                                                                                fulfill a valid request




 3 xx
            Redirection
                          Site will be redirected
                          or URL forwarding
Topics

1   LEARN ABOUT HTTP STATUS CODE
       Http status code
       1xx Informational
       2xx Success
       3xx Redirection
       4xx Client error
       5xx Server error


2   HOW TO REDIRECT YOUR URL
    •   Main reason for redirect URL
    •   Preparing stuff
           p    g
    •   Where we place the rule
    •   Rewrite rule
    •   Example 1 : non-www to www redirection
    •   Example 2 : normal redirection
    •   Example 3 : sub domain redirection
1 xx
    Informational     Server is performing
                                                                                                                       1   2
                      some further action
                      and does not yet have a
                      definitive
                      d fi i i response




 Status code                                                     Description


    100             Allow a client that is sending a request message to determine if server is willing to accept the
  continue          request.

    101
                    Server will switch protocols to those defined by the response's Upgrade header field immediately
 Switching
                    after the empty line which terminates the 101 response.
 Protocols
Topics

1   LEARN ABOUT HTTP STATUS CODE
       Http status code
       1xx Informational
       2xx Success
       3xx Redirection
       4xx Client error
       5xx Server error


2   HOW TO REDIRECT YOUR URL
    •   Main reason for redirect URL
    •   Preparing stuff
           p    g
    •   Where we place the rule
    •   Rewrite rule
    •   Example 1 : non-www to www redirection
    •   Example 2 : normal redirection
    •   Example 3 : sub domain redirection
2 xx
              Success
                                                                                                                            1   2
                            The action requested by
                            the client was
                            successful received




 Status code                                                        Description


     201
                        New resource being created.
   created


     202
                        The request has been accepted for processing.
   accepted

    203
    non-                The returned metainformation in the entity-header is not the definitive set as available from the
authoritative           origin server.
information

     204                The server has fulfilled the request but does not need to return an entity-body, and might want to
  no content            return updated metainformation.


     205                The server has fulfilled the request and the user agent should reset the document view which
reset content           caused the request to be sent.


     206
                        The server has fulfilled the partial GET request for the resource.
partial content
Topics

1   LEARN ABOUT HTTP STATUS CODE
       Http status code
       1xx Informational
       2xx Success
       3xx Redirection
       4xx Client error
       5xx Server error


2   HOW TO REDIRECT YOUR URL
    •   Main reason for redirect URL
    •   Preparing stuff
           p    g
    •   Where we place the rule
    •   Rewrite rule
    •   Example 1 : non-www to www redirection
    •   Example 2 : normal redirection
    •   Example 3 : sub domain redirection
3 xx
         Redirection
                                                                                                                      1    2
                          Site will be redirected
                          or URL forwarding




  Status code                                                     Description


      300
                       The requested resource correspond to multiple specific location.
Multiple Choices

     301
    Moved              The requested resource has been assigned to new permanent URI.
 Permanently

     302               The requested resource resides temporarily under a different URI. This response is only cacheable
    Found              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 a
   See Other
   S Oth               GET method on that resource.
                               th d    th t


     304               If the client has performed a conditional GET request and access is allowed, but the document has
 Not Modified          not been modified.


     305
                       The requested resource must be accessed through the proxy given by the location field.
   Use Proxy
1     2

Status code                                               Description


  306         The 306 status code was used in a previous version of the specification, is no longer used, and the
(Unused)      code is reserved.

   307        If the 307 status code is received in response to a request other than GET or HEAD, the user agent
Temporary     must not automatically redirect the request unless it can be confirmed by the user, since this might
 Redirect     change the conditions under which the request was issued.
Topics

1   LEARN ABOUT HTTP STATUS CODE
       Http status code
       1xx Informational
       2xx Success
       3xx Redirection
       4xx Client error
       5xx Server error


2   HOW TO REDIRECT YOUR URL
    •   Main reason for redirect URL
    •   Preparing stuff
           p    g
    •   Where we place the rule
    •   Rewrite rule
    •   Example 1 : non-www to www redirection
    •   Example 2 : normal redirection
    •   Example 3 : sub domain redirection
4 xx
        Client error
                                                                                                                      1    2
                       Error was found from
                       client side




 Status code                                                     Description


    400
                   The requested cannot be fulfilled due to bad syntax.
Bad Request


    401
                   It will happen when authentication has failed.
Unauthorized

    402
  Payment          Reserve for future use for digital cash or micro payment.
  Required

    4 3
    403
                   The q t
                   Th request was a legal request, but the server is refusing to respond t it
                                    l l q t b t th                i    f i t           d to it.
 Forbidden


    404
                   The requested resource could not be found but may be available again in the future.
 Not Found

   405
                   A request was made of a resource using a request method not supported by that resource. For example, 
Method Not
                   using GET on a form which requires data to be presented via POST.
 Allowed
1   2

  Status code                                                  Description


     406          The requested resource is only capable of generating content not acceptable according to the
Not Acceptable    Accept headers sent in the request.

     407
    Proxy
                  It need proxy authentication for accessing the site.
Authentication
  Required

     408
                  The server timed out waiting for the request.
Request Timeout


     4 9
     409
                  Indicates that the request could not be processed because of conflict in the request
                                                                                               request.
    Conflict


      410
                  Indicates that the resource requested is no longer available and will not be available again.
     Gone


      411
                  The request did not specify the length of its content.
Length Required

     412
 Precondition     The server does not meet one of the preconditions that the requester put on the request.
    Failed

      413
 Request Entity   The request is larger than the server is willing or able to process.
   Too Large
1   2

  Status code                                                   Description

     414
 Request-URI       The URI provided was too long for the server to process.
  Too Long

     415
 Unsupported       The request entity has a media type which the server or resource does not support.
 Media Type

      416
Requested Range    The client has asked for a portion of the file, but the server cannot supply that portion.
 Not Satisfiable

     417
  Expectation
  E    t ti        The
                   Th server cannot meet the requirements of the E
                                  t    t th      i     t f th Expect request-header fi ld
                                                                   t       t h d field.
    Failed

      418
                   This request is not expected to be implemented by actual HTTP servers.
           p
  I'm a teapot
Topics

1   LEARN ABOUT HTTP STATUS CODE
       Http status code
       1xx Informational
       2xx Success
       3xx Redirection
       4xx Client error
       5xx Server error


2   HOW TO REDIRECT YOUR URL
    •   Main reason for redirect URL
    •   Preparing stuff
           p    g
    •   Where we place the rule
    •   Rewrite rule
    •   Example 1 : non-www to www redirection
    •   Example 2 : normal redirection
    •   Example 3 : sub domain redirection
5 xx
        Server error
                                                                                                                            1     2
                          The server failed to
                          fulfill a valid request




 Status code                                                        Description

      500
Internal Server        A generic error message, given when no more specific message is suitable.
     Error

    501
    Not                The server either does not recognize the request method, or it lacks the ability to fulfill the request.
Implemented

     502               The server was acting as a gateway or proxy and received an invalid response from the upstream
 Bad Gateway           server.

    503
  Service
  S i                  The
                       Th server is currently unavailable (because it is overloaded or d
                                 i        tl       il bl (b           i      l d d down f maintenance).
                                                                                         for i t     )
 Unavailable

     504
                       The server was acting as a gateway or proxy and did not receive a timely response from the
   Gateway
                       upstream server.
   Timeout

     505
HTTP Version           The server does not support the HTTP protocol version used in the request.
Not Supported
1   2

  Status code                                                   Description
                                                                      p

      506
  Variant Also    Transparent content negotiation for the request results in a circular reference.
   Negotiates

      507
  Insufficient    Disk is running out of space.
    Storage

     509
Bandwidth Limit   This status code, while used by many servers, is not specified in any RFCs.
   Exceeded


      510
                  Further extensions to the request are required for the server to fulfill it.
 Not Extended
Topics

1   LEARN ABOUT HTTP STATUS CODE
       Http status code
       1xx Informational
       2xx Success
       3xx Redirection
       4xx Client error
       5xx Server error


2   HOW TO REDIRECT YOUR URL
       Main reason for redirect URL
    •   Preparing stuff
           p    g
    •   Where we place the rule
    •   Rewrite rule
    •   Example 1 : non-www to www redirection
    •   Example 2 : normal redirection
    •   Example 3 : sub domain redirection
1   2
Main reason for redirect URL

 1. Security
   Hide underlying technology – index.php
               y g            gy        p p
   Hide actual path of files – http://www.xxx.com/images/simple?photo=34



 2. Good for people
   Easy to remember – http://www.xxx.com



 3. Good for search engine
   Search engine like friendly URL – http://www.xxx.com/contact
Topics

1   LEARN ABOUT HTTP STATUS CODE
       Http status code
       1xx Informational
       2xx Success
       3xx Redirection
       4xx Client error
       5xx Server error


2   HOW TO REDIRECT YOUR URL
       Main reason for redirect URL
       Preparing stuff
           p    g
    •   Where we place the rule
    •   Rewrite rule
    •   Example 1 : non-www to www redirection
    •   Example 2 : normal redirection
    •   Example 3 : sub domain redirection
1   2
Preparing stuff




Install Apache on your web server and enable “mod_rewrite” engine

Rewrite Engine On
Topics

1   LEARN ABOUT HTTP STATUS CODE
       Http status code
       1xx Informational
       2xx Success
       3xx Redirection
       4xx Client error
       5xx Server error


2   HOW TO REDIRECT YOUR URL
       Main reason for redirect URL
       Preparing stuff
           p    g
       Where we place the rule
    •   Rewrite rule
    •   Example 1 : non-www to www redirection
    •   Example 2 : normal redirection
    •   Example 3 : sub domain redirection
1   2
Where we place the rule

 • Apache config file - httpd.conf

 • Htaccess file - .htaccess
Topics

1   LEARN ABOUT HTTP STATUS CODE
       Http status code
       1xx Informational
       2xx Success
       3xx Redirection
       4xx Client error
       5xx Server error


2   HOW TO REDIRECT YOUR URL
       Main reason for redirect URL
       Preparing stuff
           p    g
       Where we place the rule
       Rewrite rule
    •   Example 1 : non-www to www redirection
    •   Example 2 : normal redirection
    •   Example 3 : sub domain redirection
1   2
Rewrite rule
To be more understanding for rewrite rule, It’s good to familiar with the syntax and
pattern of rewrite rule.




                             Pattern                        Target               Flag
RewriteRule         ^somefile-([0-9]+).htm$         /dir/index.php?id=$1
                                                                p p                [L]
1   2
Pattern
Pattern has been used for matches the URL path and Regular expression has been used
to detect the requested URI.

Metacharacter

   Char                                                    Definition

           Use before any of the following characters to escape or null the meaning or it *  $ + [ ]
                                                                                        it.  .

    ^       Start matching at this point.

    $       End point of the match.

     .      Any character.

    []      Starts a class.

     |      Sta ts alternative atc t s|t at wou d ea
            Starts a te at ve match this|that would mean match t s o t at.
                                                          atc 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.
1   2
Class []

    Char                                                   Definition

     ^     Negates the class. [^A-Z]+ means don't match any uppercases.

          Use before any of the following characters to escape or null the meaning or it. [ ]
                        y                g                   p                    g        [+]+.

     -     Range for matching [0-9]+ [a-zA-Z]+.
1   2
Target
It can b used f replacing any matched URL.
       be   d for  l i            h d




  File-system path


  URL path
                                             could be used
                                             as a target.
  Absolute URL


  - [dash] (no substitution)
1   2
Flag
Flag can modify the behavior of a Rewrite rule.

    Char                                                     Definition

    [R]     Redirect you can add an =301 or =302 to change the type.
              d               dd                     h      h

    [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.

    [C]     Chains a rewrite rule together with the next rule
                                                         rule.

    [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.

   [NE]     Turns of normal escapes that are default in the rewrite rule.

    [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

1   LEARN ABOUT HTTP STATUS CODE
       Http status code
       1xx Informational
       2xx Success
       3xx Redirection
       4xx Client error
       5xx Server error


2   HOW TO REDIRECT YOUR URL
       Main reason for redirect URL
       Preparing stuff
           p    g
       Where we place the rule
       Rewrite rule
       Example 1 : non-www to www redirection
    •   Example 2 : normal redirection
    •   Example 3 : sub domain redirection
1   2
Example 1 : non-www to www redirection
 http://xxx.com => redirect to h
 h                   d         http://www.xxx.com


                       Match h
                       M h this URL “h //
                                    “http://xxx.com”

  RewriteEngine        On

                                                          The pattern captured
  RewriteCond       %{HTTP_HOST} ^xxx.com                inside the parentheses


  RewriteRule       ^(.*)$      http://www.xxx.com/$1     [R=301,L]




Pattern inside parentheses is     Replace with this URL   Redirect with 301 and
capture as variable “$1”                                  make this as the last
                                                          Rewrite rule.
Topics

1   LEARN ABOUT HTTP STATUS CODE
       Http status code
       1xx Informational
       2xx Success
       3xx Redirection
       4xx Client error
       5xx Server error


2   HOW TO REDIRECT YOUR URL
       Main reason for redirect URL
       Preparing stuff
           p    g
       Where we place the rule
       Rewrite rule
       Example 1 : non-www to www redirection
       Example 2 : normal redirection
    •   Example 3 : sub domain redirection
1   2
Example 2 : normal redirection
 http://xxx.com => redirect to h
 h                   d         http://yyy.com/about
                                               b


                       Match h
                       M h this URL “h //
                                    “http://xxx.com”

  RewriteEngine        On


  RewriteCond       %{HTTP_HOST} ^xxx.com


  RewriteRule       ^/(.*)$     http://yyy.com/about       [R=301,QSA,L]




Pattern inside parentheses is      Replace with this URL   Redirect with 301,
                                                                          301
capture as variable “$1” but it is                         query append string
not used for this case                                     and make this as the
                                                           last rewrite rule.
Topics

1   LEARN ABOUT HTTP STATUS CODE
       Http status code
       1xx Informational
       2xx Success
       3xx Redirection
       4xx Client error
       5xx Server error


2   HOW TO REDIRECT YOUR URL
       Main reason for redirect URL
       Preparing stuff
           p    g
       Where we place the rule
       Rewrite rule
       Example 1 : non-www to www redirection
       Example 2 : normal redirection
    •   Example 3 : sub domain redirection
1      2
Example 3 : sub domain redirection
http://xxx.com/blog/ => redirect to h
h              bl         d         http://blog.xxx.com/
                                           bl




RewriteEngine     On


RewriteRule     ^/blog/?(.*)$   http://blog.xxx.com/$1     [P,NC,L]




   Match “/blog/”
   M h “/bl /” pattern            Replace with this URL
                                  R l      i h hi          Rules
                                                           R l are served   d
                                                           through proxy, case
                                                           insensitive and make
                                                           this as the last Rewrite
                                                           rule.
References
http://www.webforgers.net/mod-rewrite/mod-rewrite-syntax.php
http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html
http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
http://en.wikipedia.org/wiki/List_of_HTTP_status_codes
http://en.wikipedia.org/wiki/URL_redirection#Manual_redirect
Thank you for watching
      y              g
my presentation




                                  Created by
                           panu ausavasereelert
                          blog: http://panu.in.th
                         email: panu@panu in th
                                panu@panu.in.th
                             twitter: @panuinth

More Related Content

Viewers also liked

The role of social care in services for people with disability
The role of social care in services for people with disabilityThe role of social care in services for people with disability
The role of social care in services for people with disabilitySocial Care Ireland
 
Lab 4 handout 043012
Lab 4 handout 043012Lab 4 handout 043012
Lab 4 handout 043012Tim Arroyo
 
Evaluation qu's 1&2
Evaluation qu's 1&2Evaluation qu's 1&2
Evaluation qu's 1&2billy-sav
 
Question 2
Question 2Question 2
Question 2Kamamor
 
S ri vs traditional aga khan rural support programme (india), locaton dangs d...
S ri vs traditional aga khan rural support programme (india), locaton dangs d...S ri vs traditional aga khan rural support programme (india), locaton dangs d...
S ri vs traditional aga khan rural support programme (india), locaton dangs d...Yogesh Bhatt
 
President of egypt - moeshesh - رئيس مصر
President of egypt - moeshesh - رئيس مصرPresident of egypt - moeshesh - رئيس مصر
President of egypt - moeshesh - رئيس مصرMohamed Shishtawy
 
Point d'avancement sur le Projet Mobilité
Point d'avancement sur le Projet MobilitéPoint d'avancement sur le Projet Mobilité
Point d'avancement sur le Projet MobilitéThe Shift Project
 
Matt Talbot Services Presentation
Matt Talbot Services PresentationMatt Talbot Services Presentation
Matt Talbot Services PresentationSocial Care Ireland
 
Social Media Best Practices
Social Media Best PracticesSocial Media Best Practices
Social Media Best PracticesWahine Media
 
AWWA/WEF Student Chapter Presentation
AWWA/WEF Student Chapter PresentationAWWA/WEF Student Chapter Presentation
AWWA/WEF Student Chapter PresentationZachary Collins
 
OER Overview (MCCLPHEI Annual Conference 6/19/14 Salem, MA)
OER Overview (MCCLPHEI Annual Conference 6/19/14 Salem, MA)OER Overview (MCCLPHEI Annual Conference 6/19/14 Salem, MA)
OER Overview (MCCLPHEI Annual Conference 6/19/14 Salem, MA)Nicole Allen
 

Viewers also liked (20)

The role of social care in services for people with disability
The role of social care in services for people with disabilityThe role of social care in services for people with disability
The role of social care in services for people with disability
 
Lab 4 handout 043012
Lab 4 handout 043012Lab 4 handout 043012
Lab 4 handout 043012
 
Undrah
UndrahUndrah
Undrah
 
Evaluation qu's 1&2
Evaluation qu's 1&2Evaluation qu's 1&2
Evaluation qu's 1&2
 
Question 2
Question 2Question 2
Question 2
 
Chad daley 1
Chad daley 1Chad daley 1
Chad daley 1
 
Sgp
SgpSgp
Sgp
 
Mi tv 2
Mi tv 2Mi tv 2
Mi tv 2
 
10
1010
10
 
Tpnº15
Tpnº15Tpnº15
Tpnº15
 
Hurricane
HurricaneHurricane
Hurricane
 
S ri vs traditional aga khan rural support programme (india), locaton dangs d...
S ri vs traditional aga khan rural support programme (india), locaton dangs d...S ri vs traditional aga khan rural support programme (india), locaton dangs d...
S ri vs traditional aga khan rural support programme (india), locaton dangs d...
 
Comun.masa.rot
Comun.masa.rotComun.masa.rot
Comun.masa.rot
 
President of egypt - moeshesh - رئيس مصر
President of egypt - moeshesh - رئيس مصرPresident of egypt - moeshesh - رئيس مصر
President of egypt - moeshesh - رئيس مصر
 
Point d'avancement sur le Projet Mobilité
Point d'avancement sur le Projet MobilitéPoint d'avancement sur le Projet Mobilité
Point d'avancement sur le Projet Mobilité
 
Matt Talbot Services Presentation
Matt Talbot Services PresentationMatt Talbot Services Presentation
Matt Talbot Services Presentation
 
Dimple bawri oct 11
Dimple bawri oct 11Dimple bawri oct 11
Dimple bawri oct 11
 
Social Media Best Practices
Social Media Best PracticesSocial Media Best Practices
Social Media Best Practices
 
AWWA/WEF Student Chapter Presentation
AWWA/WEF Student Chapter PresentationAWWA/WEF Student Chapter Presentation
AWWA/WEF Student Chapter Presentation
 
OER Overview (MCCLPHEI Annual Conference 6/19/14 Salem, MA)
OER Overview (MCCLPHEI Annual Conference 6/19/14 Salem, MA)OER Overview (MCCLPHEI Annual Conference 6/19/14 Salem, MA)
OER Overview (MCCLPHEI Annual Conference 6/19/14 Salem, MA)
 

Similar to How to redirect URL with Apache web server

REST 101: An Overview To Representational State Transfer.
REST 101: An Overview To Representational State Transfer.REST 101: An Overview To Representational State Transfer.
REST 101: An Overview To Representational State Transfer.Omar Fernando Zafe
 
HTTP Status Codes Cheat Sheet: An Exhaustive List
HTTP Status Codes Cheat Sheet: An Exhaustive ListHTTP Status Codes Cheat Sheet: An Exhaustive List
HTTP Status Codes Cheat Sheet: An Exhaustive ListMainstreethost
 
Http basics by-joshi_29_4_15-ppt
Http basics by-joshi_29_4_15-pptHttp basics by-joshi_29_4_15-ppt
Http basics by-joshi_29_4_15-pptQwinix Technologies
 
BITM3730 Networking.pdf
BITM3730 Networking.pdfBITM3730 Networking.pdf
BITM3730 Networking.pdfMattMarino13
 
BITM3730 11-1.pptx
BITM3730 11-1.pptxBITM3730 11-1.pptx
BITM3730 11-1.pptxMattMarino13
 
HTTP Request Header and HTTP Status Code
HTTP Request Header and HTTP Status CodeHTTP Request Header and HTTP Status Code
HTTP Request Header and HTTP Status CodeAbhishek L.R
 
BITM3730Week9(1).pptx
BITM3730Week9(1).pptxBITM3730Week9(1).pptx
BITM3730Week9(1).pptxMattMarino13
 
HTTP Status Codes
HTTP Status CodesHTTP Status Codes
HTTP Status CodesWebSniffer
 
21 HTTP Protocol #burningkeyboards
21 HTTP Protocol #burningkeyboards21 HTTP Protocol #burningkeyboards
21 HTTP Protocol #burningkeyboardsDenis Ristic
 
The OAuth 2.0 Authorization Framework
The OAuth 2.0 Authorization FrameworkThe OAuth 2.0 Authorization Framework
The OAuth 2.0 Authorization FrameworkSamuele Cozzi
 
Business Requirements Package
Business Requirements PackageBusiness Requirements Package
Business Requirements Packagesellingsaintlouis
 
Implementing Early Hints in Chrome - Approaches and Challenges
Implementing Early Hints in Chrome - Approaches and ChallengesImplementing Early Hints in Chrome - Approaches and Challenges
Implementing Early Hints in Chrome - Approaches and ChallengesViet-Hoang Tran
 
SFDC Outbound Integrations
SFDC Outbound IntegrationsSFDC Outbound Integrations
SFDC Outbound IntegrationsSujit Kumar
 
Php sdk-v3-async
Php sdk-v3-asyncPhp sdk-v3-async
Php sdk-v3-asyncmtdowling
 
Aditya - Hacking Client Side Insecurities - ClubHack2008
Aditya - Hacking Client Side Insecurities - ClubHack2008Aditya - Hacking Client Side Insecurities - ClubHack2008
Aditya - Hacking Client Side Insecurities - ClubHack2008ClubHack
 
Advance java session 4
Advance java session 4Advance java session 4
Advance java session 4Smita B Kumar
 

Similar to How to redirect URL with Apache web server (20)

REST 101: An Overview To Representational State Transfer.
REST 101: An Overview To Representational State Transfer.REST 101: An Overview To Representational State Transfer.
REST 101: An Overview To Representational State Transfer.
 
HTTP Status Codes Cheat Sheet: An Exhaustive List
HTTP Status Codes Cheat Sheet: An Exhaustive ListHTTP Status Codes Cheat Sheet: An Exhaustive List
HTTP Status Codes Cheat Sheet: An Exhaustive List
 
Http basics by-joshi_29_4_15-ppt
Http basics by-joshi_29_4_15-pptHttp basics by-joshi_29_4_15-ppt
Http basics by-joshi_29_4_15-ppt
 
BITM3730 Networking.pdf
BITM3730 Networking.pdfBITM3730 Networking.pdf
BITM3730 Networking.pdf
 
BITM3730 11-1.pptx
BITM3730 11-1.pptxBITM3730 11-1.pptx
BITM3730 11-1.pptx
 
HTTP Request Header and HTTP Status Code
HTTP Request Header and HTTP Status CodeHTTP Request Header and HTTP Status Code
HTTP Request Header and HTTP Status Code
 
BITM3730Week9(1).pptx
BITM3730Week9(1).pptxBITM3730Week9(1).pptx
BITM3730Week9(1).pptx
 
Web technology Unit-I Part D - message format
Web technology Unit-I  Part D - message formatWeb technology Unit-I  Part D - message format
Web technology Unit-I Part D - message format
 
HTTP Status Codes
HTTP Status CodesHTTP Status Codes
HTTP Status Codes
 
HTTP
HTTPHTTP
HTTP
 
21 HTTP Protocol #burningkeyboards
21 HTTP Protocol #burningkeyboards21 HTTP Protocol #burningkeyboards
21 HTTP Protocol #burningkeyboards
 
The OAuth 2.0 Authorization Framework
The OAuth 2.0 Authorization FrameworkThe OAuth 2.0 Authorization Framework
The OAuth 2.0 Authorization Framework
 
Business Requirements Package
Business Requirements PackageBusiness Requirements Package
Business Requirements Package
 
Implementing Early Hints in Chrome - Approaches and Challenges
Implementing Early Hints in Chrome - Approaches and ChallengesImplementing Early Hints in Chrome - Approaches and Challenges
Implementing Early Hints in Chrome - Approaches and Challenges
 
SFDC Outbound Integrations
SFDC Outbound IntegrationsSFDC Outbound Integrations
SFDC Outbound Integrations
 
Php sdk-v3-async
Php sdk-v3-asyncPhp sdk-v3-async
Php sdk-v3-async
 
OAuth: Trust Issues
OAuth: Trust IssuesOAuth: Trust Issues
OAuth: Trust Issues
 
Aditya - Hacking Client Side Insecurities - ClubHack2008
Aditya - Hacking Client Side Insecurities - ClubHack2008Aditya - Hacking Client Side Insecurities - ClubHack2008
Aditya - Hacking Client Side Insecurities - ClubHack2008
 
Demystifying OAuth 2.0
Demystifying OAuth 2.0Demystifying OAuth 2.0
Demystifying OAuth 2.0
 
Advance java session 4
Advance java session 4Advance java session 4
Advance java session 4
 

Recently uploaded

(南达科他州立大学毕业证学位证成绩单-永久存档)
(南达科他州立大学毕业证学位证成绩单-永久存档)(南达科他州立大学毕业证学位证成绩单-永久存档)
(南达科他州立大学毕业证学位证成绩单-永久存档)oannq
 
南新罕布什尔大学毕业证学位证成绩单-学历认证
南新罕布什尔大学毕业证学位证成绩单-学历认证南新罕布什尔大学毕业证学位证成绩单-学历认证
南新罕布什尔大学毕业证学位证成绩单-学历认证kbdhl05e
 
(No.1)↠Young Call Girls in Sikanderpur (Gurgaon) ꧁❤ 9711911712 ❤꧂ Escorts
(No.1)↠Young Call Girls in Sikanderpur (Gurgaon) ꧁❤ 9711911712 ❤꧂ Escorts(No.1)↠Young Call Girls in Sikanderpur (Gurgaon) ꧁❤ 9711911712 ❤꧂ Escorts
(No.1)↠Young Call Girls in Sikanderpur (Gurgaon) ꧁❤ 9711911712 ❤꧂ EscortsDelhi Escorts Service
 
E J Waggoner against Kellogg's Pantheism 8.pptx
E J Waggoner against Kellogg's Pantheism 8.pptxE J Waggoner against Kellogg's Pantheism 8.pptx
E J Waggoner against Kellogg's Pantheism 8.pptxJackieSparrow3
 
Inspiring Through Words Power of Inspiration.pptx
Inspiring Through Words Power of Inspiration.pptxInspiring Through Words Power of Inspiration.pptx
Inspiring Through Words Power of Inspiration.pptxShubham Rawat
 
Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...
Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...
Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...Authentic No 1 Amil Baba In Pakistan
 
西伦敦大学毕业证学位证成绩单-怎么样做
西伦敦大学毕业证学位证成绩单-怎么样做西伦敦大学毕业证学位证成绩单-怎么样做
西伦敦大学毕业证学位证成绩单-怎么样做j5bzwet6
 
Call Girls In Karkardooma 83770 87607 Just-Dial Escorts Service 24X7 Avilable
Call Girls In Karkardooma 83770 87607 Just-Dial Escorts Service 24X7 AvilableCall Girls In Karkardooma 83770 87607 Just-Dial Escorts Service 24X7 Avilable
Call Girls In Karkardooma 83770 87607 Just-Dial Escorts Service 24X7 Avilabledollysharma2066
 

Recently uploaded (9)

(南达科他州立大学毕业证学位证成绩单-永久存档)
(南达科他州立大学毕业证学位证成绩单-永久存档)(南达科他州立大学毕业证学位证成绩单-永久存档)
(南达科他州立大学毕业证学位证成绩单-永久存档)
 
南新罕布什尔大学毕业证学位证成绩单-学历认证
南新罕布什尔大学毕业证学位证成绩单-学历认证南新罕布什尔大学毕业证学位证成绩单-学历认证
南新罕布什尔大学毕业证学位证成绩单-学历认证
 
(No.1)↠Young Call Girls in Sikanderpur (Gurgaon) ꧁❤ 9711911712 ❤꧂ Escorts
(No.1)↠Young Call Girls in Sikanderpur (Gurgaon) ꧁❤ 9711911712 ❤꧂ Escorts(No.1)↠Young Call Girls in Sikanderpur (Gurgaon) ꧁❤ 9711911712 ❤꧂ Escorts
(No.1)↠Young Call Girls in Sikanderpur (Gurgaon) ꧁❤ 9711911712 ❤꧂ Escorts
 
E J Waggoner against Kellogg's Pantheism 8.pptx
E J Waggoner against Kellogg's Pantheism 8.pptxE J Waggoner against Kellogg's Pantheism 8.pptx
E J Waggoner against Kellogg's Pantheism 8.pptx
 
Inspiring Through Words Power of Inspiration.pptx
Inspiring Through Words Power of Inspiration.pptxInspiring Through Words Power of Inspiration.pptx
Inspiring Through Words Power of Inspiration.pptx
 
Model Call Girl in Lado Sarai Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Lado Sarai Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Lado Sarai Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Lado Sarai Delhi reach out to us at 🔝9953056974🔝
 
Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...
Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...
Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...
 
西伦敦大学毕业证学位证成绩单-怎么样做
西伦敦大学毕业证学位证成绩单-怎么样做西伦敦大学毕业证学位证成绩单-怎么样做
西伦敦大学毕业证学位证成绩单-怎么样做
 
Call Girls In Karkardooma 83770 87607 Just-Dial Escorts Service 24X7 Avilable
Call Girls In Karkardooma 83770 87607 Just-Dial Escorts Service 24X7 AvilableCall Girls In Karkardooma 83770 87607 Just-Dial Escorts Service 24X7 Avilable
Call Girls In Karkardooma 83770 87607 Just-Dial Escorts Service 24X7 Avilable
 

How to redirect URL with Apache web server

  • 1. How to redirect URL with Apache web server 1 xx 2 xx 3 xx 4 xx 5 xx Informational Success Redirection Client error Server error
  • 2. 1 2 Topics 1 LEARN ABOUT HTTP STATUS CODE  Http status code  1xx Informational  2xx Success  3xx Redirection  4xx Client error  5xx Server error 2 HOW TO REDIRECT YOUR URL • Main reason for redirect URL • Preparing stuff p g • Where we place the rule • Rewrite rule • Example 1 : non-www to www redirection • Example 2 : normal redirection • Example 3 : sub domain redirection
  • 3. Http status code It i response status code which i part of th HTTP/ standard. is t t d hi h is t f the HTTP/1.1 t d d 1 xx Informational f l Server i performing is f i some further action and does not yet have a 4 xx definitive response Client error Error was found from client side 2 xx Success The action requested by the client was 5 xx successful received Server error The server failed to fulfill a valid request 3 xx Redirection Site will be redirected or URL forwarding
  • 4. Topics 1 LEARN ABOUT HTTP STATUS CODE  Http status code  1xx Informational  2xx Success  3xx Redirection  4xx Client error  5xx Server error 2 HOW TO REDIRECT YOUR URL • Main reason for redirect URL • Preparing stuff p g • Where we place the rule • Rewrite rule • Example 1 : non-www to www redirection • Example 2 : normal redirection • Example 3 : sub domain redirection
  • 5. 1 xx Informational Server is performing 1 2 some further action and does not yet have a definitive d fi i i response Status code Description 100 Allow a client that is sending a request message to determine if server is willing to accept the continue request. 101 Server will switch protocols to those defined by the response's Upgrade header field immediately Switching after the empty line which terminates the 101 response. Protocols
  • 6. Topics 1 LEARN ABOUT HTTP STATUS CODE  Http status code  1xx Informational  2xx Success  3xx Redirection  4xx Client error  5xx Server error 2 HOW TO REDIRECT YOUR URL • Main reason for redirect URL • Preparing stuff p g • Where we place the rule • Rewrite rule • Example 1 : non-www to www redirection • Example 2 : normal redirection • Example 3 : sub domain redirection
  • 7. 2 xx Success 1 2 The action requested by the client was successful received Status code Description 201 New resource being created. created 202 The request has been accepted for processing. accepted 203 non- The returned metainformation in the entity-header is not the definitive set as available from the authoritative origin server. information 204 The server has fulfilled the request but does not need to return an entity-body, and might want to no content return updated metainformation. 205 The server has fulfilled the request and the user agent should reset the document view which reset content caused the request to be sent. 206 The server has fulfilled the partial GET request for the resource. partial content
  • 8. Topics 1 LEARN ABOUT HTTP STATUS CODE  Http status code  1xx Informational  2xx Success  3xx Redirection  4xx Client error  5xx Server error 2 HOW TO REDIRECT YOUR URL • Main reason for redirect URL • Preparing stuff p g • Where we place the rule • Rewrite rule • Example 1 : non-www to www redirection • Example 2 : normal redirection • Example 3 : sub domain redirection
  • 9. 3 xx Redirection 1 2 Site will be redirected or URL forwarding Status code Description 300 The requested resource correspond to multiple specific location. Multiple Choices 301 Moved The requested resource has been assigned to new permanent URI. Permanently 302 The requested resource resides temporarily under a different URI. This response is only cacheable Found 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 a See Other S Oth GET method on that resource. th d th t 304 If the client has performed a conditional GET request and access is allowed, but the document has Not Modified not been modified. 305 The requested resource must be accessed through the proxy given by the location field. Use Proxy
  • 10. 1 2 Status code Description 306 The 306 status code was used in a previous version of the specification, is no longer used, and the (Unused) code is reserved. 307 If the 307 status code is received in response to a request other than GET or HEAD, the user agent Temporary must not automatically redirect the request unless it can be confirmed by the user, since this might Redirect change the conditions under which the request was issued.
  • 11. Topics 1 LEARN ABOUT HTTP STATUS CODE  Http status code  1xx Informational  2xx Success  3xx Redirection  4xx Client error  5xx Server error 2 HOW TO REDIRECT YOUR URL • Main reason for redirect URL • Preparing stuff p g • Where we place the rule • Rewrite rule • Example 1 : non-www to www redirection • Example 2 : normal redirection • Example 3 : sub domain redirection
  • 12. 4 xx Client error 1 2 Error was found from client side Status code Description 400 The requested cannot be fulfilled due to bad syntax. Bad Request 401 It will happen when authentication has failed. Unauthorized 402 Payment Reserve for future use for digital cash or micro payment. Required 4 3 403 The q t Th request was a legal request, but the server is refusing to respond t it l l q t b t th i f i t d to it. Forbidden 404 The requested resource could not be found but may be available again in the future. Not Found 405 A request was made of a resource using a request method not supported by that resource. For example,  Method Not using GET on a form which requires data to be presented via POST. Allowed
  • 13. 1 2 Status code Description 406 The requested resource is only capable of generating content not acceptable according to the Not Acceptable Accept headers sent in the request. 407 Proxy It need proxy authentication for accessing the site. Authentication Required 408 The server timed out waiting for the request. Request Timeout 4 9 409 Indicates that the request could not be processed because of conflict in the request request. Conflict 410 Indicates that the resource requested is no longer available and will not be available again. Gone 411 The request did not specify the length of its content. Length Required 412 Precondition The server does not meet one of the preconditions that the requester put on the request. Failed 413 Request Entity The request is larger than the server is willing or able to process. Too Large
  • 14. 1 2 Status code Description 414 Request-URI The URI provided was too long for the server to process. Too Long 415 Unsupported The request entity has a media type which the server or resource does not support. Media Type 416 Requested Range The client has asked for a portion of the file, but the server cannot supply that portion. Not Satisfiable 417 Expectation E t ti The Th server cannot meet the requirements of the E t t th i t f th Expect request-header fi ld t t h d field. Failed 418 This request is not expected to be implemented by actual HTTP servers. p I'm a teapot
  • 15. Topics 1 LEARN ABOUT HTTP STATUS CODE  Http status code  1xx Informational  2xx Success  3xx Redirection  4xx Client error  5xx Server error 2 HOW TO REDIRECT YOUR URL • Main reason for redirect URL • Preparing stuff p g • Where we place the rule • Rewrite rule • Example 1 : non-www to www redirection • Example 2 : normal redirection • Example 3 : sub domain redirection
  • 16. 5 xx Server error 1 2 The server failed to fulfill a valid request Status code Description 500 Internal Server A generic error message, given when no more specific message is suitable. Error 501 Not The server either does not recognize the request method, or it lacks the ability to fulfill the request. Implemented 502 The server was acting as a gateway or proxy and received an invalid response from the upstream Bad Gateway server. 503 Service S i The Th server is currently unavailable (because it is overloaded or d i tl il bl (b i l d d down f maintenance). for i t ) Unavailable 504 The server was acting as a gateway or proxy and did not receive a timely response from the Gateway upstream server. Timeout 505 HTTP Version The server does not support the HTTP protocol version used in the request. Not Supported
  • 17. 1 2 Status code Description p 506 Variant Also Transparent content negotiation for the request results in a circular reference. Negotiates 507 Insufficient Disk is running out of space. Storage 509 Bandwidth Limit This status code, while used by many servers, is not specified in any RFCs. Exceeded 510 Further extensions to the request are required for the server to fulfill it. Not Extended
  • 18. Topics 1 LEARN ABOUT HTTP STATUS CODE  Http status code  1xx Informational  2xx Success  3xx Redirection  4xx Client error  5xx Server error 2 HOW TO REDIRECT YOUR URL  Main reason for redirect URL • Preparing stuff p g • Where we place the rule • Rewrite rule • Example 1 : non-www to www redirection • Example 2 : normal redirection • Example 3 : sub domain redirection
  • 19. 1 2 Main reason for redirect URL 1. Security Hide underlying technology – index.php y g gy p p Hide actual path of files – http://www.xxx.com/images/simple?photo=34 2. Good for people Easy to remember – http://www.xxx.com 3. Good for search engine Search engine like friendly URL – http://www.xxx.com/contact
  • 20. Topics 1 LEARN ABOUT HTTP STATUS CODE  Http status code  1xx Informational  2xx Success  3xx Redirection  4xx Client error  5xx Server error 2 HOW TO REDIRECT YOUR URL  Main reason for redirect URL  Preparing stuff p g • Where we place the rule • Rewrite rule • Example 1 : non-www to www redirection • Example 2 : normal redirection • Example 3 : sub domain redirection
  • 21. 1 2 Preparing stuff Install Apache on your web server and enable “mod_rewrite” engine Rewrite Engine On
  • 22. Topics 1 LEARN ABOUT HTTP STATUS CODE  Http status code  1xx Informational  2xx Success  3xx Redirection  4xx Client error  5xx Server error 2 HOW TO REDIRECT YOUR URL  Main reason for redirect URL  Preparing stuff p g  Where we place the rule • Rewrite rule • Example 1 : non-www to www redirection • Example 2 : normal redirection • Example 3 : sub domain redirection
  • 23. 1 2 Where we place the rule • Apache config file - httpd.conf • Htaccess file - .htaccess
  • 24. Topics 1 LEARN ABOUT HTTP STATUS CODE  Http status code  1xx Informational  2xx Success  3xx Redirection  4xx Client error  5xx Server error 2 HOW TO REDIRECT YOUR URL  Main reason for redirect URL  Preparing stuff p g  Where we place the rule  Rewrite rule • Example 1 : non-www to www redirection • Example 2 : normal redirection • Example 3 : sub domain redirection
  • 25. 1 2 Rewrite rule To be more understanding for rewrite rule, It’s good to familiar with the syntax and pattern of rewrite rule. Pattern Target Flag RewriteRule ^somefile-([0-9]+).htm$ /dir/index.php?id=$1 p p [L]
  • 26. 1 2 Pattern Pattern has been used for matches the URL path and Regular expression has been used to detect the requested URI. Metacharacter Char Definition Use before any of the following characters to escape or null the meaning or it * $ + [ ] it. . ^ Start matching at this point. $ End point of the match. . Any character. [] Starts a class. | Sta ts alternative atc t s|t at wou d ea Starts a te at ve match this|that would mean match t s o t at. atc 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.
  • 27. 1 2 Class [] Char Definition ^ Negates the class. [^A-Z]+ means don't match any uppercases. Use before any of the following characters to escape or null the meaning or it. [ ] y g p g [+]+. - Range for matching [0-9]+ [a-zA-Z]+.
  • 28. 1 2 Target It can b used f replacing any matched URL. be d for l i h d File-system path URL path could be used as a target. Absolute URL - [dash] (no substitution)
  • 29. 1 2 Flag Flag can modify the behavior of a Rewrite rule. Char Definition [R] Redirect you can add an =301 or =302 to change the type. d dd h h [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. [C] Chains a rewrite rule together with the next rule rule. [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. [NE] Turns of normal escapes that are default in the rewrite rule. [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.
  • 30. Topics 1 LEARN ABOUT HTTP STATUS CODE  Http status code  1xx Informational  2xx Success  3xx Redirection  4xx Client error  5xx Server error 2 HOW TO REDIRECT YOUR URL  Main reason for redirect URL  Preparing stuff p g  Where we place the rule  Rewrite rule  Example 1 : non-www to www redirection • Example 2 : normal redirection • Example 3 : sub domain redirection
  • 31. 1 2 Example 1 : non-www to www redirection http://xxx.com => redirect to h h d http://www.xxx.com Match h M h this URL “h // “http://xxx.com” RewriteEngine On The pattern captured RewriteCond %{HTTP_HOST} ^xxx.com inside the parentheses RewriteRule ^(.*)$ http://www.xxx.com/$1 [R=301,L] Pattern inside parentheses is Replace with this URL Redirect with 301 and capture as variable “$1” make this as the last Rewrite rule.
  • 32. Topics 1 LEARN ABOUT HTTP STATUS CODE  Http status code  1xx Informational  2xx Success  3xx Redirection  4xx Client error  5xx Server error 2 HOW TO REDIRECT YOUR URL  Main reason for redirect URL  Preparing stuff p g  Where we place the rule  Rewrite rule  Example 1 : non-www to www redirection  Example 2 : normal redirection • Example 3 : sub domain redirection
  • 33. 1 2 Example 2 : normal redirection http://xxx.com => redirect to h h d http://yyy.com/about b Match h M h this URL “h // “http://xxx.com” RewriteEngine On RewriteCond %{HTTP_HOST} ^xxx.com RewriteRule ^/(.*)$ http://yyy.com/about [R=301,QSA,L] Pattern inside parentheses is Replace with this URL Redirect with 301, 301 capture as variable “$1” but it is query append string not used for this case and make this as the last rewrite rule.
  • 34. Topics 1 LEARN ABOUT HTTP STATUS CODE  Http status code  1xx Informational  2xx Success  3xx Redirection  4xx Client error  5xx Server error 2 HOW TO REDIRECT YOUR URL  Main reason for redirect URL  Preparing stuff p g  Where we place the rule  Rewrite rule  Example 1 : non-www to www redirection  Example 2 : normal redirection • Example 3 : sub domain redirection
  • 35. 1 2 Example 3 : sub domain redirection http://xxx.com/blog/ => redirect to h h bl d http://blog.xxx.com/ bl RewriteEngine On RewriteRule ^/blog/?(.*)$ http://blog.xxx.com/$1 [P,NC,L] Match “/blog/” M h “/bl /” pattern Replace with this URL R l i h hi Rules R l are served d through proxy, case insensitive and make this as the last Rewrite rule.
  • 37. Thank you for watching y g my presentation Created by panu ausavasereelert blog: http://panu.in.th email: panu@panu in th panu@panu.in.th twitter: @panuinth