• Save
Apache Rewrite Rules
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Apache Rewrite Rules

on

  • 15,710 views

Basic talk about apache mod_rewrite

Basic talk about apache mod_rewrite

Statistics

Views

Total Views
15,710
Views on SlideShare
15,437
Embed Views
273

Actions

Likes
9
Downloads
0
Comments
0

8 Embeds 273

http://webonrails.com 181
http://vinsol.com 45
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 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
  • 13.
    • Thanks
    • :-)
    • http://webonrails.com