I'm using mod_rewrite with PHP4. I'd like to recover part of the rewritten url displayed in the address bar but how do I recover the whole url first? The format of my rewritten urls is: http://example.com/%something%/ e.g. http://example.com/stuff/ If I try PHP_SELF or URI_REQUEST, I get results for the url of the actual php file used and not the rewritten url. Also, AFAIK %something% isn't found in memory after the rewrite. I thought this would be simple but I just spent 90 minutes googling and surfing forums and all I've found are a few other threads that ended inconclusively. thanks
all i can think of is if you use modrewrite on domain/search/*/ and redirect it to ?search=* then you know pretty much that it's written as .../search/whatever/ not quite sure that it can be done the way your would like to though but it may be and i am just not aware of it
ansi, I'm not sure I get you. I want the user to still see the rewritten url in the address bar, but I also need to know what it is for the code. I could put a value into memory when the user click the referer link, but it seems like overkill. The rewrite *is* taking place on the server, so PHP should be able to see it
what i am saying is for example you have a search page, URLs written like www.domain.com/search/keyword/ get redirected to www.domain.com/search.php?q=keyword so in theory you have search.php that uses $_GET['q'] as the search term. now since they are at search.php you assume that they arrived there by www.domain.com/search/ since you're rewriting URLs anyways you probably wont have any direct references to search.php by itself, you would use the rewritten URL instead. following me still? so simply append the keyword ($_GET['q']) to www.domain.com/search/ and toss an extra / afterwards. voila, you have the url.
Ansi, I had to read over your suggestion a few times but now I understand. Where it breaks down is at the beginning; the 'q' parameter is no longer in memory when the page is executed after the rewrite, so I can't recover the parameter to reconstruct the rewritten url. Would you happen to know how to do a PHP memory dump, so that I can see if there's any other useful info in memory post-rewrite?
Consider this ..... RewriteEngine On RewriteRule switch/(.*)/? switch.php?switch=$1 Code (markup): some dummy code to gen some links and to show you what ansi is trying to explain <?php printf( "rewrite : /switch/%s<br />", $_GET['switch'] ); $functions = get_defined_functions( ); foreach( $functions['internal'] as $num => $name ) { printf("<a href='/switch/%s'>/switch/%s</a><br />", $name, $name ); if( $num > 20 ) { exit; } } ?> PHP: He means that you do actually have all the data available to know what url is in the address bar without actually having to programatically retrieve it. Please note SOME servers will store the rewriten url in $_SERVER['REDIRECT_URL'] NOT all servers or script or headers allow for that behaviour, it's best not to rely on it.