SlideShare a Scribd company logo
Apache mod_rewrite Dave Ross The West Suburban Chicago PHP Meetup April 3, 2008
mod_rewrite is an Apache module that takes what the browser requests and “rewrites” it into something else before the other Apache modules see it
Request Apache Request mod_rewrite Apache directives Other modules
mod_rewrite directives can go in the Apache config file (httpd.conf)‏ or in an .htaccess file if I have to put them in httpd.conf, I usually make a separate file and include it Include rewrite_rules.conf
RewriteEngine on|off RewriteCond RewriteRule The main mod_rewrite directives: They're all you need to get started.
RewriteCond {string} {pattern} [{flags}] {string} is a mod_rewrite variable.  Usually, you'll use %{REQUEST_URI}. {pattern} is:  An extended regular expression (ereg)‏ A lexical test (>, <, or =)‏ -d (is directory?)‏ -f (is regular file?)‏ -l (is symlink?)‏ other lesser-used values {flags} are NC (“no case”) or OR (“this condition or the next one”)‏
RewriteRule {pattern} {substitution} [{flags}] {pattern} is regular expression to match {substitution} is a string to replace that URL with.  It can contain variables, reference  parts of the {pattern}, or it can be the special “no substitution” string: - {flags} let you define behavior, like making the browser [R]edirect to the rewritten URL,  telling the browser the page is [G]one, or returning a certain MIME [T]ype.
For a full list of RewriteCond and RewriteRule options, read the docs at: Get really nice “cheat sheets” you can print at:
mod_rewrite is mostly used to implement “friendly” URLs. They go by many names: Friendly URLs Search Engine Friendly URLs Rational URLs Permalinks
Search engines like “friendly” URLs. How else are they supposed to know index.php?postid=6 is a different page than index.php?postid=7 ?
Programs like WordPress and Drupal have support built-in. They'll even write the .htaccess for you. How sweet is that?
Another common use of mod_rewrite is to map old URLs to new URLs
Say you change your CMS... Search engines have links, and users have bookmarks to pages in your old CMS. You don't want 404 Not Found errors when they visit those URLs again. So you use mod_rewrite to convert URLs in one format to another
Need More Info? There's a mod_rewrite tutorial at: This site not only has a tutorial, it has an active message board just about mod_rewrite:

More Related Content

KEY
URL Mapping, with and without mod_rewrite
PDF
mod_rewrite
ODP
Apache Rewrite Rules
ODP
Modern Web Development with Perl
PPT
Create a web-app with Cgi Appplication
PDF
Introduction to Perl
PDF
Apache Hacks
ZIP
Web Apps in Perl - HTTP 101
URL Mapping, with and without mod_rewrite
mod_rewrite
Apache Rewrite Rules
Modern Web Development with Perl
Create a web-app with Cgi Appplication
Introduction to Perl
Apache Hacks
Web Apps in Perl - HTTP 101

What's hot (20)

ODP
Advanced Perl Techniques
PDF
Bringing modern PHP development to IBM i (ZendCon 2016)
PPT
Xslate sv perl-2013-7-11
KEY
Mojo as a_client
ODP
Modern Perl
PDF
Demystifying Object-Oriented Programming - ZendCon 2016
PPTX
Puppet camp chicago-automated_testing2
PDF
Lies, Damn Lies, and Benchmarks
PPT
Hack in the Box Keynote 2006
ODP
HTML Templates Using Clear Silver
PDF
Perl6 in-production
PDF
Perl web frameworks
PDF
A reviravolta do desenvolvimento web
PDF
Selenium sandwich-3: Being where you aren't.
KEY
Perl: Hate it for the Right Reasons
PPT
Perl Tidy Perl Critic
PDF
Memory Manglement in Raku
PDF
今時なウェブ開発をSmalltalkでやってみる?
PPT
PHP POWERPOINT SLIDES
Advanced Perl Techniques
Bringing modern PHP development to IBM i (ZendCon 2016)
Xslate sv perl-2013-7-11
Mojo as a_client
Modern Perl
Demystifying Object-Oriented Programming - ZendCon 2016
Puppet camp chicago-automated_testing2
Lies, Damn Lies, and Benchmarks
Hack in the Box Keynote 2006
HTML Templates Using Clear Silver
Perl6 in-production
Perl web frameworks
A reviravolta do desenvolvimento web
Selenium sandwich-3: Being where you aren't.
Perl: Hate it for the Right Reasons
Perl Tidy Perl Critic
Memory Manglement in Raku
今時なウェブ開発をSmalltalkでやってみる?
PHP POWERPOINT SLIDES
Ad

Similar to Apache mod_rewrite (20)

KEY
mod_rewrite bootcamp, Ohio LInux 2011
KEY
mod_rewrite
PDF
Apache - Mod-Rewrite
PDF
mod_rewrite
PPT
Comparative Development Methodologies
PDF
Htaccess file tutorial and tips
PPTX
.htaccess
PDF
Apache and PHP: Why httpd.conf is your new BFF!
PDF
PDF
testing pdf doc
PPT
Apache
PDF
Apache Server Tutorial
PPT
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
PDF
Apache course contents
PPTX
Joomla! security 101
PDF
First there was the command line
PPT
Joomla! Day UK 2009 .htaccess
PPTX
Apache server configuration & optimization
mod_rewrite bootcamp, Ohio LInux 2011
mod_rewrite
Apache - Mod-Rewrite
mod_rewrite
Comparative Development Methodologies
Htaccess file tutorial and tips
.htaccess
Apache and PHP: Why httpd.conf is your new BFF!
testing pdf doc
Apache
Apache Server Tutorial
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Apache course contents
Joomla! security 101
First there was the command line
Joomla! Day UK 2009 .htaccess
Apache server configuration & optimization
Ad

More from Dave Ross (20)

KEY
Stylesheets of the future with Sass and Compass
KEY
HTML5 History & Features
PPT
A geek's guide to getting hired
KEY
NoSQL & MongoDB
PDF
Date and Time programming in PHP & Javascript
KEY
Simulated Eye Tracking with Attention Wizard
KEY
What's new in HTML5?
KEY
The Canvas Tag
KEY
Wordpress
PPT
Lamp Stack Optimization
PPT
The FPDF Library
PPT
FirePHP
PPT
Bayesian Inference using b8
PPT
SQL Injection in PHP
KEY
Web App Security: XSS and CSRF
KEY
The Mobile Web: A developer's perspective
KEY
Balsamiq Mockups
KEY
LAMP Optimization
KEY
Lint - PHP & Javascript Code Checking
KEY
Cufon - Javascript Font Replacement
Stylesheets of the future with Sass and Compass
HTML5 History & Features
A geek's guide to getting hired
NoSQL & MongoDB
Date and Time programming in PHP & Javascript
Simulated Eye Tracking with Attention Wizard
What's new in HTML5?
The Canvas Tag
Wordpress
Lamp Stack Optimization
The FPDF Library
FirePHP
Bayesian Inference using b8
SQL Injection in PHP
Web App Security: XSS and CSRF
The Mobile Web: A developer's perspective
Balsamiq Mockups
LAMP Optimization
Lint - PHP & Javascript Code Checking
Cufon - Javascript Font Replacement

Recently uploaded (20)

PDF
cuic standard and advanced reporting.pdf
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Machine learning based COVID-19 study performance prediction
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Electronic commerce courselecture one. Pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Empathic Computing: Creating Shared Understanding
cuic standard and advanced reporting.pdf
NewMind AI Weekly Chronicles - August'25 Week I
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
Unlocking AI with Model Context Protocol (MCP)
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Diabetes mellitus diagnosis method based random forest with bat algorithm
Machine learning based COVID-19 study performance prediction
The Rise and Fall of 3GPP – Time for a Sabbatical?
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Electronic commerce courselecture one. Pdf
Programs and apps: productivity, graphics, security and other tools
MYSQL Presentation for SQL database connectivity
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Review of recent advances in non-invasive hemoglobin estimation
Empathic Computing: Creating Shared Understanding

Apache mod_rewrite

  • 1. Apache mod_rewrite Dave Ross The West Suburban Chicago PHP Meetup April 3, 2008
  • 2. mod_rewrite is an Apache module that takes what the browser requests and “rewrites” it into something else before the other Apache modules see it
  • 3. Request Apache Request mod_rewrite Apache directives Other modules
  • 4. mod_rewrite directives can go in the Apache config file (httpd.conf)‏ or in an .htaccess file if I have to put them in httpd.conf, I usually make a separate file and include it Include rewrite_rules.conf
  • 5. RewriteEngine on|off RewriteCond RewriteRule The main mod_rewrite directives: They're all you need to get started.
  • 6. RewriteCond {string} {pattern} [{flags}] {string} is a mod_rewrite variable. Usually, you'll use %{REQUEST_URI}. {pattern} is: An extended regular expression (ereg)‏ A lexical test (>, <, or =)‏ -d (is directory?)‏ -f (is regular file?)‏ -l (is symlink?)‏ other lesser-used values {flags} are NC (“no case”) or OR (“this condition or the next one”)‏
  • 7. RewriteRule {pattern} {substitution} [{flags}] {pattern} is regular expression to match {substitution} is a string to replace that URL with. It can contain variables, reference parts of the {pattern}, or it can be the special “no substitution” string: - {flags} let you define behavior, like making the browser [R]edirect to the rewritten URL, telling the browser the page is [G]one, or returning a certain MIME [T]ype.
  • 8. For a full list of RewriteCond and RewriteRule options, read the docs at: Get really nice “cheat sheets” you can print at:
  • 9. mod_rewrite is mostly used to implement “friendly” URLs. They go by many names: Friendly URLs Search Engine Friendly URLs Rational URLs Permalinks
  • 10. Search engines like “friendly” URLs. How else are they supposed to know index.php?postid=6 is a different page than index.php?postid=7 ?
  • 11. Programs like WordPress and Drupal have support built-in. They'll even write the .htaccess for you. How sweet is that?
  • 12. Another common use of mod_rewrite is to map old URLs to new URLs
  • 13. Say you change your CMS... Search engines have links, and users have bookmarks to pages in your old CMS. You don't want 404 Not Found errors when they visit those URLs again. So you use mod_rewrite to convert URLs in one format to another
  • 14. Need More Info? There's a mod_rewrite tutorial at: This site not only has a tutorial, it has an active message board just about mod_rewrite: