Join David Powers for an in-depth discussion in this video Replacing a query string with a text value, part of PHP: Clean URLs on Apache Server.
- [Voiceover] In the previous video,…we used a number to replace a query string…that contained the primary key of a record…stored in a database.…It's just as easy to replace a query string…that contains a text value.…Let's go to Fresh Flowers.…And this page invites visitors to select the flower…to see the colors available.…So let's just click this one.…And it reloads the same page.…It's flowers.php with a query string appended to the URL.…
In this case, flower=rose.…So the page is using conditional logic…to decide whether to display the default flowers…or the selected one.…Let's create a re-write rule to match…the value assigned to flower.…So, we go to an editing program,…and in .htaccess on line three we've already…got a rule that strips the .php from the end…of arrangements.php and flowers.php.…But that rule, the matching pattern,…ends with a dollar sign.…
So it won't match anything that follows flowers.…We need to create a new rule on the next line.…So we begin with the re-write rule directive…and then the incoming pattern.…
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