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:


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]



The regex^viewbuild/([a-zA-Z0-9]+)/$ expects a trailing slash, so it will only match/viewbuild/25/. Try this one:

RewriteRule ^viewbuild/([a-zA-Z0-9]+)/?$ /viewbuild.php?id=$1 [L,QSA]

People are also looking for solutions to the problem: PHP - Using $_POST to update session array


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.