Join David Powers for an in-depth discussion in this video Creating a clean URL for any PHP file, part of PHP: Clean URLs on Apache Server.
- [Voiceover] In the previous chapter…we create a RewriteRule…to remove a dot php file name extention,…from arrangements.php and flowers.php.…It's here on line five of HT access.…The regular expression in the incoming pattern…matches the base file name for arrangements…and flowers,…and the simply add dot php in the end of it.…With just two files this works well,…but for a larger site,…it could result in a complex regex…that would need to be updated…every time a page was added or deleted.…
A more efficient technique…involves using Rewrite conditions.…So I'm going to comment out…the Rewrite rule on line five.…We still need these other more specific rules,…because most of them are handling…the final path of the clean URL,…as of valued to be past a query string.…And in the case of the orchids.php on line seven…we're not only dealing with…the non existence directory care,…but also dealing with an optional value…after orchids.…So after all these specific rules,…we can create a set of Rewrite conditions.…
So down at the bottom of the HT access…
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