1

I want to have the URL http://something.com/somestring where the somestring is picked up by the php $_GET, instead of having to write http://something.com/index.php?var=somestring and inside php using $_GET["var"].

How do I do it?

5 Answers 5

2

If you are running on Apache, you can use mod_rewrite. Other servers have different methods, but the general term us 'URL rewriting' to describe this functionality.

Sign up to request clarification or add additional context in comments.

3 Comments

For IIS there is ISAPI_REWRITE what is nearly the same as mod_rewrite but it isn't free
so does that then change the URL so php can understand what to $_GET?
Well, yes, but there is some configuration required. It kind of does an 'internal' redirect, so your page is called as index.php?face=palm, but the user accesses it via /palm. It can be as simple or as complex as you like, and work based on simple criteria or regular expressions.
0

Your question has already been answered. But to give you the common example for your case:

RewriteEngine
RewriteCond ./%{REQUEST_URI}  !-f
RewriteRule ^(\w+)$   index.php?var=$1   [L]

The first cond prevents the rule from rewriting requests to real files. The second takes any alphanumeric string and appends it as GET parameter to your script.

Comments

0

You can use .htaccess and mod_rewrite to do this, assuming you are using apache as webserver -> http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html

Comments

0

Look into .htaccess and mod_rewrite.

Comments

0

Another option would be using the $_SERVER["QUERY_STRING"]

http://something.com/index.php?=somestring

$_SERVER["QUERY_STRING"] would return "somestring"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.