i followed up multiple tutorials how to make pretty URL but never actualy make it work (prolly i didnt get something).
What i want:
From something like this:
http://www.example.com/api/v1/get.php?user=UserName&id=7Ka2la2 I want to make something like this:
http://www.example.com/UserName/get/7Ka2la2 What i did try: As I mentioned I try to follow multiple tutorials but nothing worked for me. So i try something by my self.
//.htaccess <IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^ index.php [L] </IfModule> What it does:
- it checks if the request filename isn't a file
- and checks if it isn't a directory
- then, the RewriteRule makes a call to index.php, no matter what was written in the URL
And in my index.php file it looks like this
<?php function parse_path() { $path = array(); if (isset($_SERVER['REQUEST_URI'])) { $path = explode('/', $_SERVER['REQUEST_URI']); } return $path; } $path_info = parse_path(); echo '<pre>'.print_r($path_info, true).'</pre>'; switch($path_info[1]) { case 'get': include 'get.php'; break; default: include '404.php'; } So it basicly should just split url to array and then base on URL include right file (in this example its get.php). However like this i can load a file but i have nothing in my $_GET and $_POST which make my script useless for me.
Question: My code will somehow do what i want so base on url it load content but $_GET and $_POST will not work correctly here. So my question is did I make it wrong way? If yea how should looks the right one and if not how I can access $_GET and $_POST variabiles
mod_rewritethe other way around - when you want to make your "pretty" URL actually functional :RewriteRule ^ index.php [L]is basically stripping all your GETdata.example.com/this/is/restful(which appears in the address bar) that request gets redirected (invisibly) toexample.com/index.php?path=this/is/restfulwhich the application then has to process. The problem, of course, is that you have to generate the RESTful URLs in the first place.