Reputation: 521
I am trying to GET the ID of a index.php
, I would like it to look like this:
www.mysite.com/path/<--ID goes here-->
I have tried to put this in my .htaccess
file, but it wont work!
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d # not a dir
RewriteCond %{REQUEST_FILENAME} !-f # not a file
RewriteRule ^(.*)$ index.php?uri=$1 [L]
And ofcourse I use $ID = $_GET['id'];
to get the ID.
I would also like it to work, if a vistor types the following..
www.mysite.com/<--ID goes here-->
I know a code that works for the above, but it doesn't work for the other path.
Any help would be appreciated! Thanks
Upvotes: 1
Views: 302
Reputation: 785611
You can try this rule in your DOCUMENT_ROOT/.htaccess
file:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(path)/([^/]+)/?$ /$1/index.php?id=$2 [L,QSA,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ /index.php?id=$1 [L,QSA]
Upvotes: 2
Reputation: 4494
You should use $ID = $_GET['uri']
since that's what you are adding in the RewriteRule
Upvotes: 2