How to re-write URLs on site hosted on Apache Web Server?

How to re-write URLs on a site hosted on Apache Web Server?

If your website is hosted on an Apache Web Server, you can use .htaccess, the Apache directory level configuration files, to create SEO friendly URLs.

For more detailed information about .htaccess files, please follow the tutorial on Apache official website.

Here is a basic summary to create SEO friendly URLs for dynamic pages.

If you have a dynamic page called /product.php containing a numeric variable called ID : /product.php?id=25 , .htaccess file would enable you to obtain a more SEO friendly URL structure with the format such as /product/25.

To obtain this result, use:

RewriteEngine on
RewriteRule ^/?product/([0-50]+)$ /product\.php?id=$1

To remove the extension from your filenames, you can use the code:

RewriteRule ^/?contact-us/([a-z--]+)$ /contact-us/$1\.php

An URL which have the structure http://www.website.com/contact-us/barcelona-office.php would return as http://www.website.com/contact-us/barcelona-office.

SEO Tips

PPC Tips