Join David Powers for an in-depth discussion in this video How to use mod_rewrite, part of Clean PHP URLs on Apache Server.
- View Offline
- [Voiceover] In this chapter we'll look at basic…URL rewriting, and how to use Apache mod_rewrite.…Let's begin with a quick overview of what it does.…The Apache mod_rewrite module…modifies incoming URL requests at runtime,…allowing you to map arbitrary URLs onto your file structure.…In other words, the URLs don't need…to match the names of directories or files.…One of the main advantages for database-driven sites…is that you can get rid of query strings…at the end of your URLs.…
Rewrite rules are based on regular expressions…that match patterns in the incoming URLs.…But you can achieve a great deal,…even without a deep knowledge of regular expressions.…Rules can be specified either in…the main Apache configuration file, httpd.conf…or in an .htaccess file.…Most of this course focuses on using .htaccess…because it's unusual to be able to edit…the main configuration file in a hosting environment.…
To modify URLs, the first step is…to turn on the Apache RewriteEngine.…All that involves is adding this directive…to your .htaccess or configuration file.…
Rather than checking URLs individually, David shows how to evaluate and update them sitewide with the Apache mod_rewrite module. Watch these tutorials to learn how to enable mod_rewrite on your server, understand the structure of mod_rewrite rules, remove unnecessary file extensions, convert query strings into readable numbers and text, and use rewrite maps to look up complex values without regular expressions. Plus, learn how to enhance search results and provide searchers with links to specific parts of a webpage.
- Checking your Apache setup
- Creating simple regular expressions
- Removing .php from URLs
- Replacing query strings
- Displaying clean URLs in search results
- Linking to parts of a webpage
- Creating a clean URL for any PHP file