SlideShare una empresa de Scribd logo
1 de 70
mod_rewrite and
       friends
     URL Mapping Power Tools

     Rich Bowen - SourceForge
AKA: Oh, no, not
     yet another
mod_rewrite talk
      URL Mapping Power Tools

      Rich Bowen - SourceForge
URL Mapping

 What            Directory
                 (listing)
 does that
 URL mean?    Redirect

              Proxy
  File
              Error
  Handler
mod_rewrite

Gave that talk for the last four PHP|Tek
conferences

I think half of you attended those talks

So, what can we do that's different?
Although ...



       If you actually
   *wanted* a mod_rewrite
   talk, that can probably
         be arranged.
Let's start with the
interesting stuff


We can proceed to the boring stuff as we
have time.
<If>


New in 2.4

This is the reason you've been looking for
to upgrade to 2.4
Expressions




                                              Function by vestman, on Flickr
Mathematical statement which is either true
or false

Can consider any variable that interests
you
<If "%{HTTP_HOST} != 'www.example.com'">
    Redirect permanent / http://www.example.com
</If>




             <If> can be used in any
             context (server, vhost,
              directory, .htaccess)
Goodbye mod_rewrite

Doesn't replace mod_rewrite in *all*
contexts

But it does for many of the things you're
using it for

And it's much more readable, usually
So ...
Example: hotlinking

RewriteCond %{HTTP_REFERER} 
         !www.example.com [NC]
RewriteRule .(gif|jpg|png)$ - [F,NC]
Becomes:
                     Note: Shorter is not
                    always better. I think
                      this is *clearer*


<If "%{HTTP_REFERER} !~ www.example.com">
 <If "%{REQUEST_URI} =~ .(gif|jpg|png)$">
   Require all denied
 </If>
</If>
Also
<If "-R '10.1.0.0/16'">
  # ...
</If>
<ElseIf "-R '10.0.0.0/8'">
  # ...
</ElseIf>
<Else>
  # ...
</Else>
                 -R is like
        "%{REMOTE_ADDR} -ipmatch ..."
More later
We could give examples of this all day, but
let's move on to something else ...




                                      By Roby Ferrari, on Flickr
FallbackResource


New as of 2.2.16

You all need it
You've all seen this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteBase /
 RewriteRule ^index.php$ - [L]
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule . /index.php [L]
</IfModule>

# END WordPress
You've all seen this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
 RewriteEngine On
        This bit says "If mod_rewrite
 RewriteBase /
             is enabled", and is
 RewriteRule ^index.php$ - [L]
          completely unnecessary.
 RewriteCond %{REQUEST_FILENAME} !-f
         That's probably a rant for
 RewriteCond %{REQUEST_FILENAME} !-d
                another time.
 RewriteRule . /index.php [L]
</IfModule>

# END WordPress
You've all seen this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteBase /
 RewriteRule ^index.php$ - [L]
 RewriteCond Annoying bit to keep
             %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
              mod_rewrite happy
 RewriteRule . /index.php [L]
</IfModule>

# END WordPress
You've all seen this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteBase /
 RewriteRule ^index.php$ - [L]
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
                 If it's already
 RewriteRule . /index.php [L]
            index.php, don't bother
</IfModule>

# END WordPress
You've all seen this:
# BEGIN WordPress
               If it's not a file, and it's
<IfModule mod_rewrite.c>
                 not a directory (ie, a
 RewriteEngine On
                     valid resource)
 RewriteBase /
 RewriteRule ^index.php$ - [L]
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule . /index.php [L]
</IfModule>

# END WordPress
You've all seen this:
# BEGIN WordPress
               Send everything else to
<IfModule mod_rewrite.c>
                index.php as a "front
 RewriteEngine On
                     controller"
 RewriteBase /
 RewriteRule ^index.php$ - [L]
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule . /index.php [L]
</IfModule>

# END WordPress
Or


FallbackResource /index.php
How it works


FallbackResource /index.php
         Triggers just before the error
          handlers, once other options
        have been checked. This ensures
        that existing resources (css, js,
        images, etc) continue to work as
                     desired.
How it works


FallbackResource /index.php


       Note that that's a URL path, not
        just a file name. Otherwise it
                 gets grumpy.
REQUEST_URI
FallbackResource /index.php
No need to rewrite
RewriteRule ^/(.*) /index.php?$1
# or something like that ...
                     Instead ...

   FallbackResource /index.php


$args = explode('/',
       $_SERVER['REQUEST_URI'] );
 Remember that the first character of a
        URL path is always "/"
Robert Fornal, on Flickr
        *Match

Directives: AliasMatch, RedirectMatch,
ProxyPassMatch

Containers: DirectoryMatch, LocationMatch,
FilesMatch
AliasMAtch

# Keep the images separate

AliasMatch ^/image/(.*).jpg$ 
             /files/jpg.images/$1.jpg
AliasMatch ^/image/(.*).gif$ 
             /files/gif.images/$1.gif
AliasMatch ^/image/(.*).png$ 
             /files/png.images/$1.gif
Case insensitive

 AliasMatch (?i)^/image(.*) 
   /ftp/pub/image$1
Everything but ...
RedirectMatch ^/(?!images/)(.*) 
       http://dynamic.myhost.com/$1
Everything but ...
RedirectMatch ^/(?!images/)(.*) 
       http://dynamic.myhost.com/$1



 This is called a zero-width
   assertion. Zero-width
because it doesn't capture a
        backreference
Everything but ...
RedirectMatch ^/(?!images/)(.*) 
       http://dynamic.myhost.com/$1




  Matches anything that
DOESN'T start with 'images/'
Everything but ...
RedirectMatch ^/(?!images/)(.*) 
       http://dynamic.myhost.com/$1




Result: Everything that's not
 an image goes over *there*
FilesMatch
 Recommended way to configure .php files
 with mod_php

<FilesMatch .php$>
 SetHandler application/x-httpd-php
</FilesMatch>
FilesMatch
 Recommended way to configure .php files
 with mod_php

<FilesMatch .php$>
 SetHandler application/x-httpd-php
</FilesMatch>


     Avoids .php.txt files being
       processed, for example
ProxyPassMatch


ProxyPassMatch ^/(.*.gif)$ 
  http://backend.example.com:8000/$1
ProxyPassMatch
  ProxyPassMatch ^/(.*.gif)$ 
    http://backend.example.com:8000/$1



   Security note: The target URL
shouldn't be modifiable by the URL. That is,
 there must not be any way that a cleverly
crafted URL could result in the target URL
        being something nefarious.
Consider:
ProxyPassMatch ^/(.*)$ 
 http://backend.example.com$1




          What if my URL was
   http://yourserver.com/.myserver.com/
Consider:
ProxyPassMatch ^/(.*)$ 
 http://backend.example.com$1




          What if my URL was
   http://yourserver.com/.myserver.com/
Consider:
ProxyPassMatch ^/(.*)$ 
 http://backend.example.com$1

                         Gotcha


            What if my URL was
http://backend.example.com.myserver.com/

http://yourserver.com/.myserver.com/index.php
Consider:
ProxyPassMatch ^/(.*)$ 
 http://backend.example.com$1


      Fortunately, this actually
         shouldn't work, since
  ProxyPassMatch will return a 500
     if the target URL isn't valid
   before the substitution. (ie, no
            trailing slash)
Oh, all right


We'll do some mod_rewrite stuff, because
you'd go home sad if I didn't.
Did you know ...


You can now use expr in RewriteCond, which
is practically magic
RewriteCond expr 
   "! %{HTTP_REFERER} -strmatch '*://%{HTTP_HOST}/*'"
RewriteRule ^/images - [F]
New keyword 'expr'



RewriteCond expr 
   "! %{HTTP_REFERER} -strmatch '*://%{HTTP_HOST}/*'"
RewriteRule ^/images - [F]
-strmatch is a glob,
    not a regex



RewriteCond expr 
   "! %{HTTP_REFERER} -strmatch '*://%{HTTP_HOST}/*'"
RewriteRule ^/images - [F]
RewriteCond expr 
   "! %{HTTP_REFERER} -strmatch '*://%{HTTP_HOST}/*'"
RewriteRule ^/images - [F]




         If the referer doesn't look
              like the source ...
RewriteCond expr 
   "! %{HTTP_REFERER} -strmatch '*://%{HTTP_HOST}/*'"
RewriteRule ^/images - [F]




         Yes, this is yet another way
         to prevent "hot linking" of
                    images.
RewriteMap

Table-based lookup

More programmatic lookups

Database queries
Database rewrites
   RewriteMap supports database queries in 2.4


RewriteMap myquery 
   "fastdbd:SELECT ID 
   FROM breeds WHERE name = %s"

RewriteRule ^/dogs/(.*) 
   /breeds.php?id=${myquery:$1|0} [PT]
Map Name




RewriteMap myquery 
   "fastdbd:SELECT ID 
   FROM breeds WHERE name = %s"

RewriteRule ^/dogs/(.*) 
   /breeds.php?id=${myquery:$1|0} [PT]
Argument




RewriteMap myquery 
   "fastdbd:SELECT ID 
   FROM breeds WHERE name = %s"

RewriteRule ^/dogs/(.*) 
   /breeds.php?id=${myquery:$1|0} [PT]
Default




RewriteMap myquery 
   "fastdbd:SELECT ID 
   FROM breeds WHERE name = %s"

RewriteRule ^/dogs/(.*) 
   /breeds.php?id=${myquery:$1|0} [PT]
Query is prepared and executed,
  so sql injection is mitigated, but
    you still need to be careful.




RewriteMap myquery 
   "fastdbd:SELECT ID 
   FROM breeds WHERE name = %s"

RewriteRule ^/dogs/(.*) 
   /breeds.php?id=${myquery:$1|0} [PT]
Use "fastdbd" to enable query
    caching, "dbd" to do without
               caching



RewriteMap myquery 
   "fastdbd:SELECT ID 
   FROM breeds WHERE name = %s"

RewriteRule ^/dogs/(.*) 
   /breeds.php?id=${myquery:$1|0} [PT]
Default value if there's no
     returned value. If multiple
  values, one is selected randomly




RewriteMap myquery 
   "fastdbd:SELECT ID 
   FROM breeds WHERE name = %s"

RewriteRule ^/dogs/(.*) 
   /breeds.php?id=${myquery:$1|0} [PT]
mod_proxy_html

New module in 2.4

Was available as third-party module in
earlier versions

Simplifies proxying to a back-end app
mod_proxy_html


Proxying to internal server which is
closed-source, or that you don't have time
to monkey with

Generated HTML has fully-qualified URLs:
Client
http://app.local/




                    http://example.com/
                                          <html>
                                          <a href="http://
                                          app.local">
                                          Link</a>
                                          ...
mod_proxy_html


Fixes up the HTML

Also inspects cookies, and other headers,
and fixes those
mod_proxy_express


Another new module in 2.4

Simplifies the creation of proxying a bunch
of vhosts to back-end servers
##
##express-map.txt:
##

www1.example.com http://192.168.211.2:8080
www2.example.com http://192.168.211.12:8088
www3.example.com http://192.168.212.10
##
##express-map.txt:
##

www1.example.com http://192.168.211.2:8080
www2.example.com http://192.168.211.12:8088
www3.example.com http://192.168.212.10



  httxt2dbm -i express-map.txt -o emap




      ProxyExpressDBMFile emap
mod_proxy_express


Especially awesome for a bunch of VMs,
with a front-end proxy/cache server

Avoids having a jillion ProxyPass directives
or rewrite rules
And while we're on
the subject

mod_proxy_balancer is twice as caffeinated
as it used to be
mod_proxy_balancer

<Proxy balancer://mycluster>
    BalancerMember http://192.168.1.50:80
    BalancerMember http://192.168.1.51:80
</Proxy>

ProxyPass /test balancer://mycluster
ProxyPassReverse /test balancer://mycluster
Balance By ...

Busyness




                 SuperFantastic, on Flickr
Byrequests

Bytraffic

heartbeats
Heartbeats




                                     Mark McLaughlin, on Flickr
This is new

mod_heartmonitor and mod_heartbeat
verify that a server is alive, and now you
balance by what server is more idle
Fin

rbowen@geek.net

@rbowen

 https://joind.in/6509

Más contenido relacionado

La actualidad más candente

Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl TechniquesDave Cross
 
Xslate sv perl-2013-7-11
Xslate sv perl-2013-7-11Xslate sv perl-2013-7-11
Xslate sv perl-2013-7-11Goro Fuji
 
You don’t know query - WordCamp UK Edinburgh 2012
You don’t know query - WordCamp UK Edinburgh 2012You don’t know query - WordCamp UK Edinburgh 2012
You don’t know query - WordCamp UK Edinburgh 2012l3rady
 
You Don't Know Query (WordCamp Netherlands 2012)
You Don't Know Query (WordCamp Netherlands 2012)You Don't Know Query (WordCamp Netherlands 2012)
You Don't Know Query (WordCamp Netherlands 2012)andrewnacin
 
Demystifying Object-Oriented Programming - ZendCon 2016
Demystifying Object-Oriented Programming - ZendCon 2016Demystifying Object-Oriented Programming - ZendCon 2016
Demystifying Object-Oriented Programming - ZendCon 2016Alena Holligan
 
HTML Templates Using Clear Silver
HTML Templates Using Clear SilverHTML Templates Using Clear Silver
HTML Templates Using Clear SilverPaulWay
 
Hack in the Box Keynote 2006
Hack in the Box Keynote 2006Hack in the Box Keynote 2006
Hack in the Box Keynote 2006Mark Curphey
 
Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.Workhorse Computing
 
Ruby on Rails testing with Rspec
Ruby on Rails testing with RspecRuby on Rails testing with Rspec
Ruby on Rails testing with RspecBunlong Van
 
Introduction to Modern Perl
Introduction to Modern PerlIntroduction to Modern Perl
Introduction to Modern PerlDave Cross
 
Php server variables
Php server variablesPhp server variables
Php server variablesJIGAR MAKHIJA
 
Supercharging WordPress Development in 2018
Supercharging WordPress Development in 2018Supercharging WordPress Development in 2018
Supercharging WordPress Development in 2018Adam Tomat
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐいHisateru Tanaka
 
The Joy of Smartmatch
The Joy of SmartmatchThe Joy of Smartmatch
The Joy of SmartmatchAndrew Shitov
 
Hypers and Gathers and Takes! Oh my!
Hypers and Gathers and Takes! Oh my!Hypers and Gathers and Takes! Oh my!
Hypers and Gathers and Takes! Oh my!Workhorse Computing
 

La actualidad más candente (20)

Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl Techniques
 
Xslate sv perl-2013-7-11
Xslate sv perl-2013-7-11Xslate sv perl-2013-7-11
Xslate sv perl-2013-7-11
 
You don’t know query - WordCamp UK Edinburgh 2012
You don’t know query - WordCamp UK Edinburgh 2012You don’t know query - WordCamp UK Edinburgh 2012
You don’t know query - WordCamp UK Edinburgh 2012
 
Php
PhpPhp
Php
 
You Don't Know Query (WordCamp Netherlands 2012)
You Don't Know Query (WordCamp Netherlands 2012)You Don't Know Query (WordCamp Netherlands 2012)
You Don't Know Query (WordCamp Netherlands 2012)
 
Demystifying Object-Oriented Programming - ZendCon 2016
Demystifying Object-Oriented Programming - ZendCon 2016Demystifying Object-Oriented Programming - ZendCon 2016
Demystifying Object-Oriented Programming - ZendCon 2016
 
Perl6 in-production
Perl6 in-productionPerl6 in-production
Perl6 in-production
 
HTML Templates Using Clear Silver
HTML Templates Using Clear SilverHTML Templates Using Clear Silver
HTML Templates Using Clear Silver
 
Hack in the Box Keynote 2006
Hack in the Box Keynote 2006Hack in the Box Keynote 2006
Hack in the Box Keynote 2006
 
Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.
 
Ruby on Rails testing with Rspec
Ruby on Rails testing with RspecRuby on Rails testing with Rspec
Ruby on Rails testing with Rspec
 
Introduction to Modern Perl
Introduction to Modern PerlIntroduction to Modern Perl
Introduction to Modern Perl
 
Php server variables
Php server variablesPhp server variables
Php server variables
 
Supercharging WordPress Development in 2018
Supercharging WordPress Development in 2018Supercharging WordPress Development in 2018
Supercharging WordPress Development in 2018
 
Php string function
Php string function Php string function
Php string function
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい
 
Php and MySQL
Php and MySQLPhp and MySQL
Php and MySQL
 
PHP POWERPOINT SLIDES
PHP POWERPOINT SLIDESPHP POWERPOINT SLIDES
PHP POWERPOINT SLIDES
 
The Joy of Smartmatch
The Joy of SmartmatchThe Joy of Smartmatch
The Joy of Smartmatch
 
Hypers and Gathers and Takes! Oh my!
Hypers and Gathers and Takes! Oh my!Hypers and Gathers and Takes! Oh my!
Hypers and Gathers and Takes! Oh my!
 

Destacado

XAJA - Reverse AJAX framework
XAJA - Reverse AJAX frameworkXAJA - Reverse AJAX framework
XAJA - Reverse AJAX frameworkSri Prasanna
 
Htaccess file tutorial and tips
Htaccess file tutorial and tipsHtaccess file tutorial and tips
Htaccess file tutorial and tipsImam Rosidi
 
Lithium: The Framework for People Who Hate Frameworks
Lithium: The Framework for People Who Hate FrameworksLithium: The Framework for People Who Hate Frameworks
Lithium: The Framework for People Who Hate FrameworksNate Abele
 
How to scale PHP applications
How to scale PHP applicationsHow to scale PHP applications
How to scale PHP applicationsEnrico Zimuel
 
Vulnerable Active Record: A tale of SQL Injection in PHP Framework
Vulnerable Active Record: A tale of SQL Injection in PHP FrameworkVulnerable Active Record: A tale of SQL Injection in PHP Framework
Vulnerable Active Record: A tale of SQL Injection in PHP FrameworkPichaya Morimoto
 
The Perils of Perception in 2016: Ipsos MORI
The Perils of Perception in 2016: Ipsos MORIThe Perils of Perception in 2016: Ipsos MORI
The Perils of Perception in 2016: Ipsos MORIIpsos UK
 
By Phasse - Catalogue-ing
By Phasse - Catalogue-ingBy Phasse - Catalogue-ing
By Phasse - Catalogue-ingKent Phan
 
AmyandSusan
AmyandSusanAmyandSusan
AmyandSusansgrobins
 
Learning organization may2010
Learning organization may2010Learning organization may2010
Learning organization may2010Michael Jones
 
Presentasi wwoooooooooooooookeeeeeeeee
Presentasi wwoooooooooooooookeeeeeeeeePresentasi wwoooooooooooooookeeeeeeeee
Presentasi wwoooooooooooooookeeeeeeeeeOlga Tiara
 
Web Services Catalog
Web Services CatalogWeb Services Catalog
Web Services CatalogRudolf Husar
 
Nossa Experiência - Promott
Nossa Experiência - PromottNossa Experiência - Promott
Nossa Experiência - Promottpromott12
 

Destacado (20)

XAJA - Reverse AJAX framework
XAJA - Reverse AJAX frameworkXAJA - Reverse AJAX framework
XAJA - Reverse AJAX framework
 
Htaccess file tutorial and tips
Htaccess file tutorial and tipsHtaccess file tutorial and tips
Htaccess file tutorial and tips
 
Lithium: The Framework for People Who Hate Frameworks
Lithium: The Framework for People Who Hate FrameworksLithium: The Framework for People Who Hate Frameworks
Lithium: The Framework for People Who Hate Frameworks
 
How to scale PHP applications
How to scale PHP applicationsHow to scale PHP applications
How to scale PHP applications
 
Vulnerable Active Record: A tale of SQL Injection in PHP Framework
Vulnerable Active Record: A tale of SQL Injection in PHP FrameworkVulnerable Active Record: A tale of SQL Injection in PHP Framework
Vulnerable Active Record: A tale of SQL Injection in PHP Framework
 
The Perils of Perception in 2016: Ipsos MORI
The Perils of Perception in 2016: Ipsos MORIThe Perils of Perception in 2016: Ipsos MORI
The Perils of Perception in 2016: Ipsos MORI
 
Infinity plus one
Infinity plus oneInfinity plus one
Infinity plus one
 
VW Santana Vista - Brochure
VW Santana Vista - BrochureVW Santana Vista - Brochure
VW Santana Vista - Brochure
 
By Phasse - Catalogue-ing
By Phasse - Catalogue-ingBy Phasse - Catalogue-ing
By Phasse - Catalogue-ing
 
F28 bota5
F28 bota5F28 bota5
F28 bota5
 
AmyandSusan
AmyandSusanAmyandSusan
AmyandSusan
 
CIF ppt 21.12.12
CIF ppt 21.12.12CIF ppt 21.12.12
CIF ppt 21.12.12
 
CAMPUSMATE
CAMPUSMATECAMPUSMATE
CAMPUSMATE
 
Learning organization may2010
Learning organization may2010Learning organization may2010
Learning organization may2010
 
Jst part1
Jst part1Jst part1
Jst part1
 
C11 nhandangtamgiac
C11 nhandangtamgiacC11 nhandangtamgiac
C11 nhandangtamgiac
 
Presentasi wwoooooooooooooookeeeeeeeee
Presentasi wwoooooooooooooookeeeeeeeeePresentasi wwoooooooooooooookeeeeeeeee
Presentasi wwoooooooooooooookeeeeeeeee
 
Web Services Catalog
Web Services CatalogWeb Services Catalog
Web Services Catalog
 
Nossa Experiência - Promott
Nossa Experiência - PromottNossa Experiência - Promott
Nossa Experiência - Promott
 
Oppa (13)
Oppa (13)Oppa (13)
Oppa (13)
 

Similar a URL Mapping, with and without mod_rewrite

CodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkCodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkBo-Yi Wu
 
Rush, a shell that will yield to you
Rush, a shell that will yield to youRush, a shell that will yield to you
Rush, a shell that will yield to youguestdd9d06
 
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)James Titcumb
 
[Bristol WordPress] Supercharging WordPress Development
[Bristol WordPress] Supercharging WordPress Development[Bristol WordPress] Supercharging WordPress Development
[Bristol WordPress] Supercharging WordPress DevelopmentAdam Tomat
 
Cloud Automation with Opscode Chef
Cloud Automation with Opscode ChefCloud Automation with Opscode Chef
Cloud Automation with Opscode ChefSri Ram
 
Laying the proper foundation for plugin and theme development
Laying the proper foundation for plugin and theme developmentLaying the proper foundation for plugin and theme development
Laying the proper foundation for plugin and theme developmentTammy Hart
 
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)Mike Schinkel
 
Deploy Rails Application by Capistrano
Deploy Rails Application by CapistranoDeploy Rails Application by Capistrano
Deploy Rails Application by CapistranoTasawr Interactive
 
Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)
Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)
Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)James Titcumb
 
Your own (little) gem: building an online business with Ruby
Your own (little) gem: building an online business with RubyYour own (little) gem: building an online business with Ruby
Your own (little) gem: building an online business with RubyLindsay Holmwood
 
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasmineSingle Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasminePaulo Ragonha
 
Zend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_ToolZend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_ToolGordon Forsythe
 
Childthemes ottawa-word camp-1919
Childthemes ottawa-word camp-1919Childthemes ottawa-word camp-1919
Childthemes ottawa-word camp-1919Paul Bearne
 
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)James Titcumb
 
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)arcware
 
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...King Foo
 
Nginx Workshop Aftermath
Nginx Workshop AftermathNginx Workshop Aftermath
Nginx Workshop AftermathDenis Zhdanov
 
WordPress Security - ওয়ার্ডপ্রেসের সিকিউরিটি
WordPress Security - ওয়ার্ডপ্রেসের সিকিউরিটিWordPress Security - ওয়ার্ডপ্রেসের সিকিউরিটি
WordPress Security - ওয়ার্ডপ্রেসের সিকিউরিটিFaysal Shahi
 

Similar a URL Mapping, with and without mod_rewrite (20)

CodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkCodeIgniter PHP MVC Framework
CodeIgniter PHP MVC Framework
 
Rush, a shell that will yield to you
Rush, a shell that will yield to youRush, a shell that will yield to you
Rush, a shell that will yield to you
 
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
 
[Bristol WordPress] Supercharging WordPress Development
[Bristol WordPress] Supercharging WordPress Development[Bristol WordPress] Supercharging WordPress Development
[Bristol WordPress] Supercharging WordPress Development
 
Cloud Automation with Opscode Chef
Cloud Automation with Opscode ChefCloud Automation with Opscode Chef
Cloud Automation with Opscode Chef
 
Laying the proper foundation for plugin and theme development
Laying the proper foundation for plugin and theme developmentLaying the proper foundation for plugin and theme development
Laying the proper foundation for plugin and theme development
 
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
 
Deploy Rails Application by Capistrano
Deploy Rails Application by CapistranoDeploy Rails Application by Capistrano
Deploy Rails Application by Capistrano
 
Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)
Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)
Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)
 
Your own (little) gem: building an online business with Ruby
Your own (little) gem: building an online business with RubyYour own (little) gem: building an online business with Ruby
Your own (little) gem: building an online business with Ruby
 
Mojolicious
MojoliciousMojolicious
Mojolicious
 
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasmineSingle Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
 
Zend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_ToolZend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_Tool
 
Childthemes ottawa-word camp-1919
Childthemes ottawa-word camp-1919Childthemes ottawa-word camp-1919
Childthemes ottawa-word camp-1919
 
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
 
QA for PHP projects
QA for PHP projectsQA for PHP projects
QA for PHP projects
 
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
 
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...
 
Nginx Workshop Aftermath
Nginx Workshop AftermathNginx Workshop Aftermath
Nginx Workshop Aftermath
 
WordPress Security - ওয়ার্ডপ্রেসের সিকিউরিটি
WordPress Security - ওয়ার্ডপ্রেসের সিকিউরিটিWordPress Security - ওয়ার্ডপ্রেসের সিকিউরিটি
WordPress Security - ওয়ার্ডপ্রেসের সিকিউরিটি
 

Más de Rich Bowen

Why your employees should contribute to Open Source
Why your employees should contribute to Open SourceWhy your employees should contribute to Open Source
Why your employees should contribute to Open SourceRich Bowen
 
Don't be a jerk
Don't be a jerkDon't be a jerk
Don't be a jerkRich Bowen
 
Write A Better FM - Ohio Linux 2011
Write A Better FM - Ohio Linux 2011Write A Better FM - Ohio Linux 2011
Write A Better FM - Ohio Linux 2011Rich Bowen
 
mod_rewrite bootcamp, Ohio LInux 2011
mod_rewrite bootcamp, Ohio LInux 2011mod_rewrite bootcamp, Ohio LInux 2011
mod_rewrite bootcamp, Ohio LInux 2011Rich Bowen
 
Apache Wizardry - Ohio Linux 2011
Apache Wizardry - Ohio Linux 2011Apache Wizardry - Ohio Linux 2011
Apache Wizardry - Ohio Linux 2011Rich Bowen
 
Write a better FM
Write a better FMWrite a better FM
Write a better FMRich Bowen
 
Apache Cookbook - TekX Chicago 2010
Apache Cookbook - TekX Chicago 2010Apache Cookbook - TekX Chicago 2010
Apache Cookbook - TekX Chicago 2010Rich Bowen
 

Más de Rich Bowen (8)

The apacheway
The apachewayThe apacheway
The apacheway
 
Why your employees should contribute to Open Source
Why your employees should contribute to Open SourceWhy your employees should contribute to Open Source
Why your employees should contribute to Open Source
 
Don't be a jerk
Don't be a jerkDon't be a jerk
Don't be a jerk
 
Write A Better FM - Ohio Linux 2011
Write A Better FM - Ohio Linux 2011Write A Better FM - Ohio Linux 2011
Write A Better FM - Ohio Linux 2011
 
mod_rewrite bootcamp, Ohio LInux 2011
mod_rewrite bootcamp, Ohio LInux 2011mod_rewrite bootcamp, Ohio LInux 2011
mod_rewrite bootcamp, Ohio LInux 2011
 
Apache Wizardry - Ohio Linux 2011
Apache Wizardry - Ohio Linux 2011Apache Wizardry - Ohio Linux 2011
Apache Wizardry - Ohio Linux 2011
 
Write a better FM
Write a better FMWrite a better FM
Write a better FM
 
Apache Cookbook - TekX Chicago 2010
Apache Cookbook - TekX Chicago 2010Apache Cookbook - TekX Chicago 2010
Apache Cookbook - TekX Chicago 2010
 

Último

Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 

Último (20)

Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 

URL Mapping, with and without mod_rewrite

  • 1. mod_rewrite and friends URL Mapping Power Tools Rich Bowen - SourceForge
  • 2. AKA: Oh, no, not yet another mod_rewrite talk URL Mapping Power Tools Rich Bowen - SourceForge
  • 3. URL Mapping What Directory (listing) does that URL mean? Redirect Proxy File Error Handler
  • 4. mod_rewrite Gave that talk for the last four PHP|Tek conferences I think half of you attended those talks So, what can we do that's different?
  • 5. Although ... If you actually *wanted* a mod_rewrite talk, that can probably be arranged.
  • 6. Let's start with the interesting stuff We can proceed to the boring stuff as we have time.
  • 7. <If> New in 2.4 This is the reason you've been looking for to upgrade to 2.4
  • 8. Expressions Function by vestman, on Flickr Mathematical statement which is either true or false Can consider any variable that interests you
  • 9. <If "%{HTTP_HOST} != 'www.example.com'"> Redirect permanent / http://www.example.com </If> <If> can be used in any context (server, vhost, directory, .htaccess)
  • 10. Goodbye mod_rewrite Doesn't replace mod_rewrite in *all* contexts But it does for many of the things you're using it for And it's much more readable, usually
  • 12. Example: hotlinking RewriteCond %{HTTP_REFERER} !www.example.com [NC] RewriteRule .(gif|jpg|png)$ - [F,NC]
  • 13. Becomes: Note: Shorter is not always better. I think this is *clearer* <If "%{HTTP_REFERER} !~ www.example.com"> <If "%{REQUEST_URI} =~ .(gif|jpg|png)$"> Require all denied </If> </If>
  • 14. Also <If "-R '10.1.0.0/16'"> # ... </If> <ElseIf "-R '10.0.0.0/8'"> # ... </ElseIf> <Else> # ... </Else> -R is like "%{REMOTE_ADDR} -ipmatch ..."
  • 15. More later We could give examples of this all day, but let's move on to something else ... By Roby Ferrari, on Flickr
  • 16. FallbackResource New as of 2.2.16 You all need it
  • 17. You've all seen this: # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress
  • 18. You've all seen this: # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On This bit says "If mod_rewrite RewriteBase / is enabled", and is RewriteRule ^index.php$ - [L] completely unnecessary. RewriteCond %{REQUEST_FILENAME} !-f That's probably a rant for RewriteCond %{REQUEST_FILENAME} !-d another time. RewriteRule . /index.php [L] </IfModule> # END WordPress
  • 19. You've all seen this: # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index.php$ - [L] RewriteCond Annoying bit to keep %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d mod_rewrite happy RewriteRule . /index.php [L] </IfModule> # END WordPress
  • 20. You've all seen this: # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d If it's already RewriteRule . /index.php [L] index.php, don't bother </IfModule> # END WordPress
  • 21. You've all seen this: # BEGIN WordPress If it's not a file, and it's <IfModule mod_rewrite.c> not a directory (ie, a RewriteEngine On valid resource) RewriteBase / RewriteRule ^index.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress
  • 22. You've all seen this: # BEGIN WordPress Send everything else to <IfModule mod_rewrite.c> index.php as a "front RewriteEngine On controller" RewriteBase / RewriteRule ^index.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress
  • 24. How it works FallbackResource /index.php Triggers just before the error handlers, once other options have been checked. This ensures that existing resources (css, js, images, etc) continue to work as desired.
  • 25. How it works FallbackResource /index.php Note that that's a URL path, not just a file name. Otherwise it gets grumpy.
  • 27. No need to rewrite RewriteRule ^/(.*) /index.php?$1 # or something like that ... Instead ... FallbackResource /index.php $args = explode('/', $_SERVER['REQUEST_URI'] ); Remember that the first character of a URL path is always "/"
  • 28. Robert Fornal, on Flickr *Match Directives: AliasMatch, RedirectMatch, ProxyPassMatch Containers: DirectoryMatch, LocationMatch, FilesMatch
  • 29. AliasMAtch # Keep the images separate AliasMatch ^/image/(.*).jpg$ /files/jpg.images/$1.jpg AliasMatch ^/image/(.*).gif$ /files/gif.images/$1.gif AliasMatch ^/image/(.*).png$ /files/png.images/$1.gif
  • 30. Case insensitive AliasMatch (?i)^/image(.*) /ftp/pub/image$1
  • 31. Everything but ... RedirectMatch ^/(?!images/)(.*) http://dynamic.myhost.com/$1
  • 32. Everything but ... RedirectMatch ^/(?!images/)(.*) http://dynamic.myhost.com/$1 This is called a zero-width assertion. Zero-width because it doesn't capture a backreference
  • 33. Everything but ... RedirectMatch ^/(?!images/)(.*) http://dynamic.myhost.com/$1 Matches anything that DOESN'T start with 'images/'
  • 34. Everything but ... RedirectMatch ^/(?!images/)(.*) http://dynamic.myhost.com/$1 Result: Everything that's not an image goes over *there*
  • 35. FilesMatch Recommended way to configure .php files with mod_php <FilesMatch .php$> SetHandler application/x-httpd-php </FilesMatch>
  • 36. FilesMatch Recommended way to configure .php files with mod_php <FilesMatch .php$> SetHandler application/x-httpd-php </FilesMatch> Avoids .php.txt files being processed, for example
  • 37. ProxyPassMatch ProxyPassMatch ^/(.*.gif)$ http://backend.example.com:8000/$1
  • 38. ProxyPassMatch ProxyPassMatch ^/(.*.gif)$ http://backend.example.com:8000/$1 Security note: The target URL shouldn't be modifiable by the URL. That is, there must not be any way that a cleverly crafted URL could result in the target URL being something nefarious.
  • 39. Consider: ProxyPassMatch ^/(.*)$ http://backend.example.com$1 What if my URL was http://yourserver.com/.myserver.com/
  • 40. Consider: ProxyPassMatch ^/(.*)$ http://backend.example.com$1 What if my URL was http://yourserver.com/.myserver.com/
  • 41. Consider: ProxyPassMatch ^/(.*)$ http://backend.example.com$1 Gotcha What if my URL was http://backend.example.com.myserver.com/ http://yourserver.com/.myserver.com/index.php
  • 42. Consider: ProxyPassMatch ^/(.*)$ http://backend.example.com$1 Fortunately, this actually shouldn't work, since ProxyPassMatch will return a 500 if the target URL isn't valid before the substitution. (ie, no trailing slash)
  • 43. Oh, all right We'll do some mod_rewrite stuff, because you'd go home sad if I didn't.
  • 44. Did you know ... You can now use expr in RewriteCond, which is practically magic
  • 45. RewriteCond expr "! %{HTTP_REFERER} -strmatch '*://%{HTTP_HOST}/*'" RewriteRule ^/images - [F]
  • 46. New keyword 'expr' RewriteCond expr "! %{HTTP_REFERER} -strmatch '*://%{HTTP_HOST}/*'" RewriteRule ^/images - [F]
  • 47. -strmatch is a glob, not a regex RewriteCond expr "! %{HTTP_REFERER} -strmatch '*://%{HTTP_HOST}/*'" RewriteRule ^/images - [F]
  • 48. RewriteCond expr "! %{HTTP_REFERER} -strmatch '*://%{HTTP_HOST}/*'" RewriteRule ^/images - [F] If the referer doesn't look like the source ...
  • 49. RewriteCond expr "! %{HTTP_REFERER} -strmatch '*://%{HTTP_HOST}/*'" RewriteRule ^/images - [F] Yes, this is yet another way to prevent "hot linking" of images.
  • 51. Database rewrites RewriteMap supports database queries in 2.4 RewriteMap myquery "fastdbd:SELECT ID FROM breeds WHERE name = %s" RewriteRule ^/dogs/(.*) /breeds.php?id=${myquery:$1|0} [PT]
  • 52. Map Name RewriteMap myquery "fastdbd:SELECT ID FROM breeds WHERE name = %s" RewriteRule ^/dogs/(.*) /breeds.php?id=${myquery:$1|0} [PT]
  • 53. Argument RewriteMap myquery "fastdbd:SELECT ID FROM breeds WHERE name = %s" RewriteRule ^/dogs/(.*) /breeds.php?id=${myquery:$1|0} [PT]
  • 54. Default RewriteMap myquery "fastdbd:SELECT ID FROM breeds WHERE name = %s" RewriteRule ^/dogs/(.*) /breeds.php?id=${myquery:$1|0} [PT]
  • 55. Query is prepared and executed, so sql injection is mitigated, but you still need to be careful. RewriteMap myquery "fastdbd:SELECT ID FROM breeds WHERE name = %s" RewriteRule ^/dogs/(.*) /breeds.php?id=${myquery:$1|0} [PT]
  • 56. Use "fastdbd" to enable query caching, "dbd" to do without caching RewriteMap myquery "fastdbd:SELECT ID FROM breeds WHERE name = %s" RewriteRule ^/dogs/(.*) /breeds.php?id=${myquery:$1|0} [PT]
  • 57. Default value if there's no returned value. If multiple values, one is selected randomly RewriteMap myquery "fastdbd:SELECT ID FROM breeds WHERE name = %s" RewriteRule ^/dogs/(.*) /breeds.php?id=${myquery:$1|0} [PT]
  • 58. mod_proxy_html New module in 2.4 Was available as third-party module in earlier versions Simplifies proxying to a back-end app
  • 59. mod_proxy_html Proxying to internal server which is closed-source, or that you don't have time to monkey with Generated HTML has fully-qualified URLs:
  • 60. Client http://app.local/ http://example.com/ <html> <a href="http:// app.local"> Link</a> ...
  • 61. mod_proxy_html Fixes up the HTML Also inspects cookies, and other headers, and fixes those
  • 62. mod_proxy_express Another new module in 2.4 Simplifies the creation of proxying a bunch of vhosts to back-end servers
  • 64. ## ##express-map.txt: ## www1.example.com http://192.168.211.2:8080 www2.example.com http://192.168.211.12:8088 www3.example.com http://192.168.212.10 httxt2dbm -i express-map.txt -o emap ProxyExpressDBMFile emap
  • 65. mod_proxy_express Especially awesome for a bunch of VMs, with a front-end proxy/cache server Avoids having a jillion ProxyPass directives or rewrite rules
  • 66. And while we're on the subject mod_proxy_balancer is twice as caffeinated as it used to be
  • 67. mod_proxy_balancer <Proxy balancer://mycluster> BalancerMember http://192.168.1.50:80 BalancerMember http://192.168.1.51:80 </Proxy> ProxyPass /test balancer://mycluster ProxyPassReverse /test balancer://mycluster
  • 68. Balance By ... Busyness SuperFantastic, on Flickr Byrequests Bytraffic heartbeats
  • 69. Heartbeats Mark McLaughlin, on Flickr This is new mod_heartmonitor and mod_heartbeat verify that a server is alive, and now you balance by what server is more idle

Notas del editor

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n
  57. \n
  58. \n
  59. \n
  60. \n
  61. \n
  62. \n
  63. \n
  64. \n
  65. \n
  66. \n
  67. \n
  68. \n
  69. \n
  70. \n