0

I have a huge amount of content that is stored in a MySQL database, which powers my app. I would like to make this info available online to provide content for non-app users as well as increase my website ranking.

The backend of the app is run on PHP/MySQL. I therefore would like to use PHP to generate these pages (is this the correct method?). I guess the PHP would take the structure of the url, for instance www.xxxx.com/viewer/**venue**/**id** where the parts in ** ** are variable. How do I get PHP to route the request based on these?

  • 1
    URL Rewriting; [URL rewriting with PHP](http://stackoverflow.com/questions/16388959/url-rewriting-with-php) – Alex K. Oct 07 '14 at 14:54

2 Answers2

1

Probably the best and most efficient method is to use URL rewriting within Apache. Add the following code to your .htaccess file (or create one if it doesn't exist) in your root folder:

RewriteEngine On
RewriteRule ^/viewer/([^/]+)/([^/]+)/?$ viewer.php?venue=$1&id=$2 [L]

Now, create a viewer.php file inside your root. You can then access the variables as part of the $_GET super-global as follows:

$venue = $_GET['venue'];
$id = $_GET['id'];

Please be advised that you should SQL injection in your code, and sanitize these inputs accordingly.

BenM
  • 52,573
  • 26
  • 113
  • 168
0

Depends on your web server.

If you're using PHP5-FPM with Nginx:

location /viewer {
  fastcgi_pass unix:/var/run/php5-fpm.sock;
  fastcgi_param SCRIPT_FILENAME /path/to/viewer.php;
  include fastcgi_params;
}

Would probably do it. Then in PHP, you would need to explode your $_SERVER['REQUEST_URI'] path after /viewer and run your logic based on that.

Example:

<?
$parts = explode("/", $_SERVER['REQUEST_URI']);
$i=0;
while($parts[$i] != 'viewer'){
  unset($parts[$i]);
  $i++;
}
if($parts[$i] == 'viewer') unset($parts[$i]);
$parts = array_values($parts);
var_dump($parts);
?>

You should see an array of all the values after your /viewer/ (venue and ID).

glambert
  • 96
  • 2
  • 16