Create SEO Friendly URLs Rewrite Using Htaccess And Mod_Rewrite

Share:

Create SEO Friendly URLs Rewrite Using Htaccess And Mod_Rewrite. For those of you who use wordpress platform would not be difficult to change the URL structure blog to be more seo friendly because the blog platform itself is already provided the settings menu, so we just simply choose to use the proper url structure.
Create SEO Friendly URL Rewrite Using .Htaccess And Mod_Rewrite Create SEO Friendly URL Rewrite Using .Htaccess And Mod_RewriteInversely proportional to the CMS which has been providing the url setup specifically, for those of you who make your own website from database creation, CMS to setup the URL structure, will definitely need the basic ability of url rewrite. That’s why in this post we will try to discuss it.

Create SEO Friendly URLs Rewrite Using Htaccess And Mod_Rewrite

In changing the structure to be more seo friendly url, we will use apache mod_rewrite and htaccess to run these commands on the server website.

Learn Mod_Rewrite Formula
First, we learn how to use mod_rewrite module. The following simple formula of mod_rewrite :

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^path/([......]+)/$ page.php?id=$1
</IfModule> 

Description :
<IfModule mod_rewrite.c> : opening in mod_rewrite
</IfModule> : closing in mod_rewrite
RewriteEngine on : url rewrite command to the web server
RewriteRule : command to create a new rule
^ : opening in rule mod_rewrite
$ : closing in rule mod_rewrite
path : destination folder
( ) : where to put a replacement rule
[……… ] : pattern replacement rule
– [0-9] : only numbers
– [A-Z] : only lowercase letters
– [a-z] : only uppercase letters
– [A-Za-z] or [a-zA-Z] : lowercase & uppercase letters
– [a-zA-Z0-9] : numbers, lowercase & uppercase
+ : character in the pattern of a replacement rule could be more than 1
page.php : page that will rewrite
?id= : querystring
$1 : writing patterns for variables that will be replaced. Written like this when the url pattern that replaced in the form of a dynamic url.

Create SEO Friendly URL
After studying the formula of mod_rewrite on .htaccess, the next is applied. To more understand how to create a SEO friendly URL, the following example of url rewrite :
Example URL Rewrite for page.php?id=10 to page-10.html
Here’s an example url rewrite, from a dynamic url to static url with html format :

RewriteEngine on
RewriteRule ^page-([0-9]+)\.html$ page.php?id=$1

Note : in front of a dot (.) on the pattern of a replacement rule should be added to the \, so the result is like the example above.
Example URL Rewrite for page.php?id=10 to page/title-post-in-id-10/
Here’s an example url rewrite, from a dynamic url to static url with html path format :

RewriteEngine on
RewriteRule ^page/([a-zA-Z0-9]+)/$ page.php?id=$1

Example URL Rewriting for page.php to page.html
If we just want to change the file format, for its application we’ve discussed this in a post : create dynamic sitemap. Writing formulas of mod_rewrite is easy enough in .htaccess file, you simply need to add the following code :

RewriteEngine on
RewriteRule ^page\.html$ page.php

Because this page is a static url then do not need to write down $1 since there is no query string in it.

When you have successfully completed the writing of the formula for url rewrite, the next is save into .htaccess file and see the results. Open the replacement url eg: example.com/page/title-post/, if the browser shows the same page with the previous url that url rewrite process has been successful, but if we see a 404 error page or Not Found warning, it shows the url rewrite yet successfully. The solution is, you check the condition of mod_rewrite in your website server, whether it has been enabled or not. And careful in using mod_rewrite in the .htaccess file website.

Discussion on how to create seo friendly url rewrite has been completed, if there are any questions, additions and corrections, please let us know using the comment box. We will wait.
Thanks for reading Create SEO Friendly URLs Rewrite Using Htaccess And Mod_Rewrite

[Tutorial.World.Edu]

8 thoughts on “Create SEO Friendly URLs Rewrite Using Htaccess And Mod_Rewrite

Leave a Reply

Your email address will not be published. Required fields are marked *