How to rewrite and get ID from a URL:
I am using a Ticket Script that gets the content from mysql database by ID. And i was wondering If we could get the ID from url by only typing the site.com/ID HERE.
Our Main URL looks like: site.com/index.php?id=1A2VD4
But how to READ and GET the ID using URL: site.com/1A2VD4
The Htaccess I am using:
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?id=$1½
RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?id=$1
I tried a lot different GET methods and Regular Expression in my php code, but not luck at all / Centos / Apache 2.2! I will be appereciated if I could get some help!
Thanks in advance
You can use this code in root's .htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/?$ /index.php?id=$1 [L,QSA]
Inside index.php
you can this id by using $_GET['id']