Join David Powers for an in-depth discussion in this video Creating a clean URL for search results, part of PHP: Clean URLs on Apache Server.
- [Voiceover] The header of each page in the example site…contains a search form at the top right.…Enter a value in there, say, "Lily," submit the form,…and it displays the results if any matches are found.…Submitting the form loads results .php.…With the search term appended to…the end of the URL as a query strength.…Let's see how we can change that to a clean URL.…We'll begin by examining how the database's been set up.…I've got that open in phpMyAdmin.…
There are four tables, arrangements, flowers,…search2arrangements, and searchterms.…If we browse searchterms, each search term is…the name of a flower in the plural.…The database query uses light with wildcard characters,…so searching for either "rose" or "roses" will match.…But the plural of some words, like, "lilies,"…involves a change of spelling.…And some flowers might be referred…to in different ways.…These are listed in the alternative column.…
However, it's the value in these searchterm…column that will be used to create the clean URL.…Each search term has a primary key, search_id,…
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