0

Is it possible to implement permalink Structure in a Custom PHP Product? If so could someone guide me how to do so.

I have bunch of PHP Files where head.php is being called initially.

I have introduced a variable admin_id in all the SQL Statements and to introduce the variable in insert and select the command i have introduced the variable as admin_id='$admin_id' in SQL Statements.

I want the variable to be assigned on the basis of Permalink i.e. http://localhost/admin_id/page_name.php. Here the admin_name is the custom permalink variable in the custom structure and page_name.php is the. page in the /var/www/html folder

Shahrukh Khan
  • 316
  • 1
  • 3
  • 15

1 Answers1

1

I would advise having all requests go through a single entry point which would then parse the URL and do the routing. I would suggest you check how Code Igniter handles routing. Most MVC frameworks use a similar principle. This way you are not dealing with so many rewrite rules in your .htaccess file.

In your .htaccess in your root folder you would have this:

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

Then index.php would be responsible for loading a routing class and handling your requests. Your routing class could then have a map of URL patterns that you want and where you want to route them. Alternatively you can setup something similar to code igniter where http://domain.com/controllername/methodname will automatically route your to controllername->methodname().

Tim Hysniu
  • 1,446
  • 13
  • 24
  • thanks for your help. I would like to indicate here that admin_id in URL is a dynamic variable whose value is stored in database and cookies – Shahrukh Khan Feb 19 '16 at 13:49
  • could you plese inidcate the script similar to code igniter – Shahrukh Khan Feb 19 '16 at 14:37
  • This might be a bit hard to read if you are just starting up: https://github.com/bcit-ci/CodeIgniter/blob/2.2-stable/system/core/Router.php However, if you want a simpler solution you can 1) come up with a permalink structure you like, 2) parse the query string after index.php. For example $1 could have this format "controller/method/parameters" 3) use parsed parameters to route to correct views. eg. [controller] goes to controller.php, which in turn executes method() with [parameters] as input – Tim Hysniu Feb 19 '16 at 19:19