• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Apache Rewrite Rules
 

Apache Rewrite Rules

on

  • 15,444 views

Basic talk about apache mod_rewrite

Basic talk about apache mod_rewrite

Statistics

Views

Total Views
15,444
Views on SlideShare
15,173
Embed Views
271

Actions

Likes
9
Downloads
0
Comments
0

8 Embeds 271

http://webonrails.com 181
http://vinsol.com 43
http://www.slideshare.net 39
http://blog.rubyonrails.co.in 3
http://cullect.com 2
http://pre-deploy.vinsol.com 1
https://duckduckgo.com 1
http://www.slashdocs.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as OpenOffice

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Apache Rewrite Rules Apache Rewrite Rules Presentation Transcript

    • Apache Re-write Rules
    • What?
      • Powerful mechanism
        • Hiding Actual URLs
        • Redirecting
        • Reformatting request URLs
    • Why?
      • Search engine friendly URLs
      • User Friendly URLs
        • Easy to remember
      • Hide underlying technology
        • index.php, index.axp, index.pl
      • Hide actual path of files
    • What we need?
      • Apache compiled with mod_rewrite module
      • mod_rewrite module should be enabled
      • RewriteEngine on
    • What does mod_rewrite do?
      • It catches URLs that meet specific
      • conditions, and rewrites them as it was
      • told to do.
    • But how does it do that?
      • Example:
      • RewriteRule ^/shortcut$ /complicated/url/here
      • <IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^/shortcut$ /complicated/url/here
      • </IfModule>
    • The Structure of RewriteRule
      • RewriteRule Pattern Substitution [OptionalFlags]
    • What are OptionalFlags?
      • Not mandatory
      • Surrounded in square brackets
      • Comma separated
      • Commonly used flags:
        • F - Forbidden. The user will receive a 403 error.
        • L - Last Rule. No more rules will be proccessed if this one was successful.
        • R[=code] – Redirect.
        • NC – No Case
    • More condition using RewriteCond
      • RewriteCond directive defines a rule condition
      • Preserve RewriteRule with one or more RewriteCond directives
        • RewriteEngine On
        • RewriteCond %{HTTP_REFERER} !^$ [NC]
        • RewriteCond %{HTTP_REFERER} !^http://domain.com [NC]
        • RewriteCond %{HTTP_REFERER} !^http://www.domain.com [NC]
        • RewriteCond %{HTTP_REFERER} !^http://xxx.yyy.zzz.100 [NC]
        • RewriteRule ^.*$ http://www.domain.com/ [R,L]
    • Control Flow
    • Server Variables
      • %{ NAME_OF_VARIABLE }
      • HTTP_USER_AGENT
      • HTTP_REFERER,
      • HTTP_HOST
      • REQUEST_METHOD
      • REMOTE_HOST
      • QUERY_STRING
      • HTTPS
      • SERVER_PORT
      • etc...
    • Some Examples:
      • RewriteRule ^products/([0-9][0-9])/$ /product.php?prodID=$1
      • RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]
      • RewriteRule .? http://www.example.com%{REQUEST_URI} [R=301,L]
      • RewriteRule ^/blog/?(.*)$ http://blog.domain.com/$1 [P,NC,L]
      • RewriteCond %{TIME_HOUR}%{TIME_MIN} >0700
      • RewriteCond %{TIME_HOUR}%{TIME_MIN} <1900
      • RewriteRule ^foo.html$ foo.day.html
      • RewriteRule ^foo.html$ foo.night.html
      • Thanks
      • :-)
      • http://webonrails.com