Generate SEO friendly URL in PHP. A website URL is a crucial thing for SEO and audience. URL has the primary role in User Experiences and SEO. Search engines are rank a webpage for well optimized and User-friendly. SEO friendly URL is one of a vital Search engine recommendation element.
Clean URL structure is a primary SEO method for WordPress websites, E-commerce sites, Blogs, Membership site, etc. We can adjust our whole site URL structure in the WordPress dashboard with simple steps with a WordPress website.
But this guide was not only for WordPress websites; this is also for Dynamic PHP websites. Directly we are going to use PHP on our WordPress website and PHP websites database to adjust our URL with the help of .htacces. If you are using a dynamic PHP website, you need to create the .htacess file.
The .htacess is the core of a WordPress and PHP websites. A WordPress website builder was built with PHP and SQL codings. You made any changes in your WordPress dashboard than that action causes the shift in .htacess. WordPress website is similarly like basic PHP dynamic websites, but WordPress was a CMS engine.
Generating SEO friendly URL with PHP is we are going to use some PHP method in the .htaccess file, Then those methods were making the change in a website database. That PHP method was “ mod_rewrite.” We can use this method to create dynamic and clean URLs.
Before starting modifications of your site URL, you need to know one crucial thing, That was If your web hosting was run on “Apache servers” this PHP modification can run smoothly. If your site was hosted on Windows server, please don’t do this modification. If you do this on Windows server, then your website must be crash, and you will lose website for sure.
You want t increase your site SEO performance?
Please read our recent articles
Generate SEO friendly URL in PHP
I have listed two kinds of URL which can show the difference between SEO friendly and not SEO friendly.
- Bad URL: yoursite.com/page1.php?category=3&product=64
- Optimized URL: yoursite.com/blog/home-products/
The second kind of URL was having the higher authority of user-friendly and SEO friendly. So we need to create our URL clean structured.
Follow these below step to create optimized SEO friendly URL in PHP.
Please be sure about your website database because you made the change in URL without knowing the product and categories id, then you will lose your product URL paths, So please be sure about product names and category names are unique in the database.
First, you need to get all the product and categories id in the database, then you need to replace all the old URL to new clean URL with the h third step.
In this step, we are going to use PHP mod_rewite method to make a shift in our website with the .htaccess file with following rule
RewriteRule /(.*)/(.*)/$ page.php?firstcategory=$1&firstproduct=$2
the (.*) pulls the elements out and puts them in variables $1 and $2.
In the step 3 was getting the information data from the database to the category and product name. This is why we need to check our database columns and table id are unique.
Like following rule:
Before: “select * from database_table where categegory_id=’$category’ and product_id=’$product'”
After: “select * from database_table where categegory_name=’$category’ and product_name=’$product'”
This method preferred for an E-commerce site which has lot database tables and columns. If you are using any kind of PHP coded websites, then this method will help you generate SEO Friendly URL in PHP.
I know this guide not entirely accurate, but It needs more pieces of information. anyway, I have shared my little PHP knowledge with you guys. I hope this article can help create SEO friendly URL in PHP. If you like this article, please share with on social media. If you any kind of doubts, please let us know on comments.