unknown os platform
how to write PHP SEO friendly URLs without htaccess | Whats-online.info
whats-online-info

how to write PHP SEO friendly URLs without htaccess


how
2016/12/31 / Science and Tutorials

Tutorial how to build SEO friendly URLs in PHP without rewriting using .htaccess file. See an example





how to write PHP SEO friendly URLs without HTACCESS


Hi, guys, today I would like to discuss re-writing part of a URL to be optimizable on search engines, i.e., (SEO friendly) and also to be user-friendly in PHP without .HTACCESS.



For example

URL one

http://whats-online.info/guides-and-info/76/app store optimization on google play for Higher Downloads/

URL two

http://whats-online.info/guides-and-info/76/app%20store%20optimization%20on%20google%20play%20for%20Higher%20Downloads/

to

URL three

http://whats-online.info/guides-and-info/76/app-store-optimization-on-google-play-for-Higher-Downloads/

For URL one
Represents the original URL. 

For URL two
The URL spaces have been encoded to percentage followed by an ASCII value (hexadecimal value).

- %20 encodes a space
- %30 encodes the number 0 
- %3b encodes semicolon and so on.

URL three is the final pretty URL after being rewritten in PHP.

This URL is SEO friendly and looks appealing to the eyes of most internet users. Most site visitors who visit a website from a search engine are mostly directed by the content of the meta title, meta description, and the kind the of the URL. 

Let us code


PHP example

<?PHP   $text = "app store optimization on google play for Higher Downloads";      $link = "http://whats-online.info/guides-and-info/76/";     $url = "http://whats-online.info/guides-and-info/76/app store optimization on google play for Higher Downloads/";    echo"Re-write </br>".$url."<br/> to <br/>".$link."".pre_replace($text);         function pre_replace($var){ $variable = preg_replace('~[^-\w]+~', '-', $var); $variable=trim($variable, "-");  return $variable; } ?>

The above function rewrites part of a URL to SEO and user-friendly in PHP and returns a pretty URL.
It re-writes all special characters with dashes as shown in the output example below.

Output

Re-write  http://whats-online.info/guides-and-info/76/app store optimization on google play for Higher Downloads/ to  http://whats-online.info/guides-and-info/76/app-store-optimization-on-google-play-for-Higher-Downloads

I hope this tutorial has helped you so much. Subscribe to our newsletter to get the latest updates direct to your mailbox or like or follow us on Twitter, Facebook and Google+.













You may also like:


Leave a comment












Subscribe to get replies direct to your mailbox

Submit comment