Join David Powers for an in-depth discussion in this video Using RewriteBase, part of Clean PHP URLs on Apache Server.
- [Voiceover] In this video we'll take a look…at the RewriteBase directive,…which sets the base URL for directory rewrites.…When using mod_rewrite in an htaccess file,…both the incoming pattern and the substitute location…are treated as relative paths.…In this example site, htaccess is in the handp folder.…So in this first RewriteRule,…the incoming pattern is looking for arrangements…or flowers in the handp folder…and if there's a match, the substitute location is either…arrangements.php or flowers.php in the same folder.…
As long as relative paths are used,…there's no need to specify RewriteBase,…but there's no harm in doing so.…The directive needs to precede the RewriteRules…and it's basically a shorthand way of creating…a site root relative link to the substitute location…in multiple RewriteRules.…So let's add it after the RewriteEngine…and before the RewriteRules.…So it's RewriteBase written all as one word.…You then follow it with the file path from the site root.…
In my testing setup, I'm using rewrite,…which is a subfolder of the local testing server root.…
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