SEO Friendly URLs with PHP

Article 43 in PHP

<< Back
2020-08-26 01:30:46 from bugfish
SEO Friendly URLs with PHP
PHP / URL Request Handling
Last Review on: 2022-08-07 03:57:09 | Hits: 671

ModRewrite needs to be enabled in apache2 by executing:
a2enmod rewrite

Modify your HTaccess File like this if index.php is your main php File:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?i=$1 [L,QSA]

  For example, if the user enters the URL yourdomain.ending/wiki/testcategorie
you can fetch the url parameters like this in your PHP Script:

     $location = explode("/", htmlspecialchars(@$_GET["i"]));

Location is now a array with the URL values inside it.

In our example

The array would be like:

location[0] = wiki
location[1] = testcategorie

Now you can load your modules with a switch/case loop or do anything else what you need to do with that
URL informations.


I do not guarantee the reliability of the information given here, the code described on this page is executed at your own risk and in the event of damage or other unforeseeable consequences I am in no way responsible or liable.


Currently 2 Upvotes!

captcha image
System - 2022-08-17 03:19:16
Thanks for visiting my page and have a nice day!
Staff may be in trouble!
Switch: NONE | Arrive: NONE
This Website is using Session Cookies for Site Functionality and AWStats.