Reputation: 23
I want my PHP file to pass: mysite.com/?id=ABC123abc
to mysite.com/ABC123abc
I've tried this code but probably is wrong:
$request = parse_url($_SERVER['REQUEST_URI']);
$path = $request["path"];
$_GET['id'] = $path; //my server returns error 404 - not found
Googled it about and haven't found anything, sorry if is duplicated question.
Upvotes: 1
Views: 412
Reputation: 38
In your site,you can use the .htaccess
file (he is used to make commands to Apache) on the folder of your project, inside him, put the code to Rewrite your URL:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([0-9]+)/?$ index.php?id=$1 [NC,L]
The RewriteEngine is a mechanism where each write of the url, the request is rewritten otherwise, which you specify.
On documentation of Apache you can look more of the RewriteEngine.
Upvotes: 2
Reputation: 1829
you can done this things using htaccess
Create SEO Friendly URLs With Htaccess Mod Rewrite
Example : http://parthmy007.in/user/123
Now you want to access 123
n as parameter using id
so for this you have to wright htaccess file
Open NotePad (yes, the windows notepad) > File > Save As > Change the “Save as Type” to “All Files” > enter “.htaccess” as the name and press Save. You’ve created a htacces file.
Create your own rewrite rule
RewriteEngine On
RewriteRule ^user/([0-9]+) user.php?id=$1 [NC, L]
Upvotes: 0