php - Using $_GET with clean URL's
I know this has been asked many a time, but i cannot find the answers I'm looking for.
Basic bit of URL rewriting but first time doing it.
example url:
domain.com/viewbuild.php?id=25
Desired:
domain.com/viewbuild/25
Attempted htaccess code:
RewriteRule ^viewbuild/([a-zA-Z0-9]+)/$ viewbuild.php?id=$1 [L,QSA]
However, I am trying to use:
$id = $_GET['id'];
But i am getting errors with this for undefined index.
I thought because i am rewriting the URL that GET variables would still work?
Thanks. Craig.
Edit as requested, full .htaccess.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^viewbuild/([a-zA-Z0-9]+)/?$ /viewbuild.php?id=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [L,QSA]
Answer
Solution:
The regex
^viewbuild/([a-zA-Z0-9]+)/$
expects a trailing slash, so it will only match/viewbuild/25/
. Try this one: