php - Getting rewritten url's value

628

lets say I have url like this:www.domain.com/csdc3ac5w and I want to get all characters after slash. I have rewritten url with htaccess.

How do I achieve that? I tried with $_GET and no success.

466

Answer

Solution:

If the script you are using to access the$_GET variable is called "script.php" then your rule will look like this:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9]+)$ /script.php?id=$1 [L,QSA]

And then in yourscript.php script, you'll be able to get the characters after the slash through$_GET['id'].

People are also looking for solutions to the problem: PHP Shopping Cart list only one item

Source

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.