Join David Powers for an in-depth discussion in this video Removing .php from the URL, part of PHP: Clean URLs on Apache Server.
- [Voiceover] This is arrangements.php…in the h and p example site.…From this point onwards, you need to work in the h and p…folder of the exercise files.…The folders for each video that have begin and end folders…contain only files that change.…So let's take a look at arrangements.php in a browser.…If we click "Flowers," it takes us to flowers.php.…"Care for Orchids" takes us to orchids.php,…and "Arrangements" takes us back to the original page,…arrangements.php.…
The first step most people take towards clean URLs…is to remove the .php from the file name.…A common way to do that is…to create a separate directory for each page…and rename the file index.php.…That definitely works, but you end up…with a huge number of directories,…and every file with the same name.…Let's see how to do it with mod_rewrite,…so back to my editing program.…And the first step is to create an ht access file.…But where should we put it?…If we put it here in the site root,…that will affect the whole site.…
That's useful for directives that affect every page,…
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