Apache Rewrite Rules

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    4 Favorites

    Apache Rewrite Rules - Presentation Transcript

    1. Apache Re-write Rules
    2. What?
      • Powerful mechanism
        • Hiding Actual URLs
        • Redirecting
        • Reformatting request URLs
    3. 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
    4. What we need?
      • Apache compiled with mod_rewrite module
      • mod_rewrite module should be enabled
      • RewriteEngine on
    5. What does mod_rewrite do?
      • It catches URLs that meet specific
      • conditions, and rewrites them as it was
      • told to do.
    6. But how does it do that?
      • Example:
      • RewriteRule ^/shortcut$ /complicated/url/here
      • <IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^/shortcut$ /complicated/url/here
      • </IfModule>
    7. The Structure of RewriteRule
      • RewriteRule Pattern Substitution [OptionalFlags]
    8. 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
    9. 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]
    10. Control Flow
    11. Server Variables
      • %{ NAME_OF_VARIABLE }
      • HTTP_USER_AGENT
      • HTTP_REFERER,
      • HTTP_HOST
      • REQUEST_METHOD
      • REMOTE_HOST
      • QUERY_STRING
      • HTTPS
      • SERVER_PORT
      • etc...
    12. 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

    + Akhil BansalAkhil Bansal, 2 years ago

    custom

    3548 views, 4 favs, 4 embeds more stats

    Basic talk about apache mod_rewrite

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 3548
      • 3449 on SlideShare
      • 99 from embeds
    • Comments 0
    • Favorites 4
    • Downloads 0
    Most viewed embeds
    • 81 views on http://webonrails.com
    • 13 views on http://vinsol.com
    • 3 views on http://blog.rubyonrails.co.in
    • 2 views on http://cullect.com

    more

    All embeds
    • 81 views on http://webonrails.com
    • 13 views on http://vinsol.com
    • 3 views on http://blog.rubyonrails.co.in
    • 2 views on http://cullect.com

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories