PHP

how to make seo friendly url using php

Utilizing URLs on your site that are program friendly is straight forward and straight forward to try to to because of PHP and Apache. we’ll be utilizing permalinks that get obviate all the nasty $_GET data that trails the top of most PHP scripts. An example of a SEO unfriendly URL we’ll clean is:

http://www.domaincom/post.php?id=123&title=seo-php-url

Using a combination of Apache’s ForceType directive, the PHP explode() function and PHP’s PATH_INFO variable we will easily turn the sample URL into:

http://www.domain.com/post/123/seo-php-url

This not only helps our website’s SEO (search engine optimization), but also accomplishes a security concept is understood as “security by obscurity”. By obscuring the very fact that our internet site is employing a PHP script, we may detract potential hackers from trying to find exploits within our scripts.

Follow below code for

Step1: First remove all special character from url

use this function to clean your url


$title=trim(htmlspecialchars($_POST['title'], ENT_QUOTES));
function clean($title) {
   $string = str_replace(' ', '-', $title); // Replaces all spaces with hyphens.
   $string = preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.

   return preg_replace('/-+/', '-', $string); // Replaces multiple hyphens with single one.
    }

 $slug=strtolower(clean($title));

Explanation Of above code

in $title you store form title value and remove space from both end and Convert the predefined characters “<” (less than) and “>” (greater than) to HTML entities

and most important to use clean function .

In this function you just need to pass title value and use this function value in $slug ou your desire url valriable

just it

Basant

Recent Posts

How to Center submit button of wpForm

You must navigate to Settings » General first. Add wpf-center to the Form CSS Class…

8 months ago

How to add Marquee on any website wordpress,PHP,HTML,eBlogger ?

if you want to add marquee on any website (wordpress,PHP,HTML,Blogger). you just need to follow…

8 months ago

How to Autoplay and Loop YouTube Videos in WordPress

First Method: Use below code to play youtube video in loop and most important is…

1 year ago

How to Disable WP JSON Rest API in WordPress without plugin ?

just add below code in wordpress theme function.php file at the bottom -------------------------------------------------- Add the…

1 year ago