1

www.something.com/?user, where "user" is a php file, is there any way to add query string parameters to it?

Have failed with:

www.something.com/?user?id=1

www.something.com/?user&id=1

www.something.com/?user/id=1

Have seen this topic: Get URL query string

but this is not exactly what I'm after...thanks

Riwi
  • 81
  • 11

1 Answers1

2

The way to do it with the php extension intact would be:

www.something.com/user.php?id=1

You then use:

$userID = $_GET['id'];

If you want to drop the PHP extension, you can do this with a rewrite in the htaccess: This is pretty generic as it depends on your web-server, but something like:

RewriteRule ^www\.something\.com/user\.php$ /www.something.com/user?&%{QUERY_STRING}

Or you could just drop using the PHP extension on all of the files to keep it neat using something like:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)$ $1.php [NC,L] 

This will rewrite all of your php extensions so this:

something.com/someFileName

Will automagically be read as

something.com/someFileName.php

To which you can still use:

something.com/someFileName?someQueryParameter=someValue
Stephen
  • 395
  • 1
  • 15