Forum Moderators: phranque
RewriteBase / is the default and can be omitted. RewriteRule should be looking for gases.php and the preceding RewriteCond should be testing QUERY_STRING or THE_REQUEST for cid=1 and gases=nitrogen. RewriteRule target URL should contain protocol and domain name.
Query Strings
The Query String, also known as a Parameter, is the part of an url after the question mark. Question = query.
By default, rewrites simply ignore the query string. That is, mod_rewrite stashes the query in a safe place, does its stuff to the part before the question mark, and then reappends the original query.
Changing a Query
#1 To delete a query, add a ? to the end of your rewrite target.
#2 To replace a query—or create a new one—add ?blahblah to the rewrite target. The blahblah can be either literal text, or stuff you captured earlier. (#1 and #2 are really the same thing: you're just replacing the query with either something or nothing.)
#3 To add to an existing query, again put ?blahblah at the end of the target, but also add [QSA] to your flags (the bracketed items at the end of the Rule). It stands for "Query String Append", meaning that the blahblah is to be added to the existing query—if any—instead of replacing it.
Getting the Query
You only need to retrieve the original query if
#1 you want the rewrite to behave differently depending on what the query was
or
#2 you need to change or delete the query
Add a Condition that says
RewriteCond %{QUERY_STRING} blahblah
using your ordinary Regular Expressions, anchors and ! as needed.
To test whether there was a query at all
RewriteCond %{QUERY_STRING} .
which simply means "If the query contains at least one character of any kind".
If you need to capture any of the query, use parentheses as usual. In the rewrite target, the captures will be %1, %2 etc instead of $1, $2 etc, because they are coming from a Condition instead of the Rule. Each set is separately numbered, so the first capture from the Rule will still be $1.
I can't seem to get it working. I'm interested in finding out what is stored in the QUERY_STRING. Is there a quick and dirty way to do it?
It just seems like the Rewrite is not removing the "?" from the url.#1 To delete a query, add a ? to the end of your rewrite target.
$statusCode to a three digit number before calling the include file when calling it from your error document pages. <?php
# Error Event Logging 2012-05-24 (logger.php)
$oldSetting= ignore_user_abort( TRUE );// otherwise can screw-up logfile
if( !empty( $GLOBALS[ '_SERVER' ])) {
$_SERVER_ARRAY= '_SERVER';
} elseif( !empty( $GLOBALS[ 'HTTP_SERVER_VARS' ])) {
$_SERVER_ARRAY= 'HTTP_SERVER_VARS';
} else {
$_SERVER_ARRAY= 'GLOBALS';
}
$requestHost= ${$_SERVER_ARRAY}[ 'SERVER_NAME' ];
if(stristr($requestHost, 'example.co.uk')) {
if(stristr($requestHost, 'dev')) {
define( '_DIRECTORY', '/var/www/vhosts/example.co.uk/subdomains/dev/httpdocs/includes/logfiles/' );
$site = 'dev';
} else if(stristr($requestHost, 'www')) {
define( '_DIRECTORY', '/var/www/vhosts/example.co.uk/httpdocs/includes/logfiles/' );
$site = 'www';
} else if(!stristr($requestHost, 'dev') && !stristr($requestHost, 'www')) {
define( '_DIRECTORY', '/var/www/vhosts/example.co.uk/httpdocs/includes/logfiles/' );
$site = 'www';
}
}
define( '_LOGFILE','errorlog' . date('-Y-m-') . $site . '-' . $statusCode . '.txt' );
#define( '_LOGFILE','errorlog' . date('-Y-m-') . $site . '.txt' ); // all in one
define( '_LOGMAXLINES','3000' );
global ${$_SERVER_ARRAY};
$logFile= _DIRECTORY . _LOGFILE;
$datetime= date( 'Y-m-d H:i:s O' );
$remoteIP= ${$_SERVER_ARRAY}[ 'REMOTE_ADDR' ];
$requestURI= ${$_SERVER_ARRAY}[ 'REQUEST_URI' ];
$referer= ( isset( ${$_SERVER_ARRAY}[ 'HTTP_REFERER' ]))
? ${$_SERVER_ARRAY}[ 'HTTP_REFERER' ]
: '<unknown referer>';
$userAgent= ( isset( ${$_SERVER_ARRAY}[ 'HTTP_USER_AGENT' ]))
? ${$_SERVER_ARRAY}[ 'HTTP_USER_AGENT' ]
: '<unknown user agent>';
if(preg_match('#(Opera\ [0-9]+\.[0-9]+)#',trim($userAgent), $extracted)) {
$agent = $extracted[1];
} elseif(preg_match('#^(Opera[^(\ ]+)#',trim($userAgent), $extracted)) {
$agent = $extracted[1];
} elseif(preg_match('#^(Xenu.*)#',trim($userAgent), $extracted)) {
$agent = $extracted[1];
} elseif(preg_match('#compatible;\ ([^;]+)#',$userAgent, $extracted)) {
$agent = $extracted[1];
} elseif(preg_match('#^([^\ ]+\ )+([^\(\)]+)#',trim($userAgent), $extracted)) {
$agent = $extracted[2];
} else {
$agent = '<see notes>';
}
$remoteIP= str_pad($remoteIP, 15);
$agent= str_pad($agent, 22);
$requestHost= str_pad($requestHost, 26, " ", STR_PAD_LEFT);
$requestURI= str_pad($requestURI, 80);
$referer= str_pad($referer, 110);
$userAgent= str_pad($userAgent, 120);
$logLine= $datetime . " - " . $remoteIP . " - " . $agent . " - ". $statusCode . " - ". $requestHost . " - ". $requestURI . " - ". $referer . " - ". $userAgent . "\n";
$log= file( $logFile );// flock() disabled in some kernels (eg 2.4)
if( $fp = fopen( $logFile, 'a' )) {// tiny danger of 2 threads interfering; live with it
if( count( $log ) >= _LOGMAXLINES ) {// otherwise grows like Topsy
fclose( $fp );// fopen,fclose put close together as possible
while( count( $log ) >= _LOGMAXLINES ) array_shift( $log );
array_push( $log, $logLine );
$logLine= implode( '', $log );
$fp= fopen( $logFile, 'w' );
}
fputs( $fp, $logLine );
fclose( $fp );
}
exit();
ignore_user_abort( $oldSetting );
?>
RewriteRule ^(.*) %1 [QSA,L]
and this is the resulting url I get: http://example.com/iphone?/iphone
So what am I doing wrong?
but, im not able to go EXTENSIONLESS