views:

83

answers:

3

I'm using Apache rewrite_mod to have all test after the URL adress go into parameter text using the following in the .htaccess file

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?text=$1 [L,QSA]

which works if I have www.example.com/some_text but doesn't when I have www.example.com/some_text/some other text

I want to have in the text parameter the whole request: "some_text/some other text" not only "some other text".

Can this be done?

A: 

I'm using this and it works perfectly:

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php/$0 [PT,L]
Jan Hančič
+1  A: 

I'd let apache/php sort this out:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L]

PHP stores all info you may need in $_SERVER

$_SERVER['REQUEST_URI']   // Original uri with original query string
$_SERVER['REDIRECT_QUERY_STRING'] // Original query string
$_SERVER['REDIRECT_URL']  // Original uri without query string

This method will leave $_GET / $_POST / $_REQUEST etc. in tact.

stroop
It's $_SERVER['QUERY_STRING'], but thanks anyway.
travis
Good point, they are identical. (Although i believed the REDIRECT_ version to contain the original one, but it doesn't.)
stroop
A: 

$_SERVER['QUERY_STRING'] will contain the query string.

Click Upvote