1

Why isn't the query string added to the GET array when using clean urls? Eg. Using /foo/bar?stack=overflow and the $_GET['stack'] variable is empty.

I'm implementing clean urls with this code:

$request = rawurldecode($_SERVER['REQUEST_URI']);

// Extracts the index.php file path (eg. /my_app)
// There is no need to specify the path to index.php as the script handles it
$path_to_index = str_ireplace($_SERVER['DOCUMENT_ROOT'].'/', '', $_SERVER['SCRIPT_FILENAME']);
$path_to_index = str_ireplace('/'.basename($_SERVER['SCRIPT_FILENAME']), '', $path_to_index);

    // Get rid of the path to index.php
$request = str_ireplace($path_to_index, '', $request);

// Get rid of index.php in the URL
$request = str_ireplace(basename($_SERVER['SCRIPT_FILENAME']), '', $request);

// Our URL is now clean so we can explode
$request = explode('/', $request);

// Delete empty and reindex
$request = array_values(array_filter($request)); 
3
  • How are you getting the clean url effect? Commented Jul 6, 2012 at 21:26
  • Are you using URL rewriting in a .htaccess file? Commented Jul 6, 2012 at 21:26
  • It depends on how you've implemented the URL rewriting, doesn't it? Commented Jul 6, 2012 at 21:27

3 Answers 3

2

If using RewriteRules in a .htaccess

At the end of your RewriteRule line put [QSA] like this:

RewriteRule (.*) index.php?stuff=$1 [QSA]

QSA flag info: http://httpd.apache.org/docs/2.2/rewrite/flags.html#flag_qsa

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

Comments

0

Maybe it's b/c you're not using $_GET ?? GET isn't a variable, but that should work just fine...

2 Comments

Well, sorry for omitting "$_". Of course I meant $_GET['stack]. I thought you guys would fill in the blanks.
well it's clear that should work, perhaps I'd rephrase the question since query params usually aren't associated with 'pretty urls'; maybe something like "$_GET not working, how?"
0

You probalby forget to use underscore ("_") in the global variable name.

Try tu use $_GET['stack'].

1 Comment

I omitted the "$_". I thought you guys would fill in the blanks. Then again stupid of me to thing you guys where mind readers...

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.