Your SlideShare is downloading. ×
Apache Rewrite Rules
Apache Rewrite Rules
Apache Rewrite Rules
Apache Rewrite Rules
Apache Rewrite Rules
Apache Rewrite Rules
Apache Rewrite Rules
Apache Rewrite Rules
Apache Rewrite Rules
Apache Rewrite Rules
Apache Rewrite Rules
Apache Rewrite Rules
Apache Rewrite Rules
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Apache Rewrite Rules

10,614

Published on

Basic talk about apache mod_rewrite

Basic talk about apache mod_rewrite

Published in: Technology, Design
0 Comments
9 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
10,614
On Slideshare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
0
Comments
0
Likes
9
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

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

×