SEF URL using htaccess and PHP

SEF URL are search engine friendly URL, which help to get rid of ugly and difficult to read URL as following

www.myweb.com/products.php?slug=product_name

Search engine does not prefer such non SEF URL. While it prefer SEF URL, which are nice and easy to read as following

www.myweb.com/product_name

One of the most helpful functionality of the htaccess file is that you can create sef URL in PHP. You can use it to redirect one URL to another or use it to create a broad sweeping change to all URLs on your website. The htaccess file uses apache mod_rewrite module to do this job.

In this post, I was experienced with generating SEF URLs using htaccess and PHP. If you look into root folder of common CMS like Joomla, you will find there is htaccess . txt there which uses it to make SEF URLs. You can also read that file to understand it’s rules that how it works.

So you may learn htaccess rules and its syntax from their official site, but I will describe my project in this post which will show my experience as well as if someone want to learn he can take advantage too. And learn that how can we create SEO Friendly URL using . htaccess

How to Create SEO Friendly URL using . htaccess

STEP 1: Login to your cPanel Account. Navigate to File Manage under Files section. Browse to public_html folder & open . htaccess on editor.

STEP 2: Suppose you have got a dynamic URL like www.myweb.com/products.php?slug=product_name which you need to convert to a SEO Friendly URL. Well, write the codes below in your . htaccess file to perform this task

Options +FollowSymLinks

RewriteEngine On

RewriteRule ^product/([A-Za-z0-9-_]+)/?$  products.php?slug=$1 [NC,L]

 

Now after adding this code into htaccess file, it will turn URL into SEF URL.

So

www.myweb.com/products.php?slug=product_name

Will be

www.myweb.com/product_name

Which is preferred by search engines like Google etc.

So if you have custom PHP website and it needs to have SEF URL using htaccess and PHP. Just ask me.