views:

33

answers:

1

is it possible to use mathematical operators in .htaccess file? for example i want to redirect a page with id=100 to a page with id=30 ?

+1  A: 

Assuming you're talking about query strings, yes.

To redirect http://example.com/page.php?id=100 to http://example.com/page.php?id=30 you would do this:

RewriteEngine On
RewriteCond %{QUERY_STRING} id=100
RewriteRule page.php page.php?id=30 [R=301,L]

Edit: AFAIK, it's not possible to do calculations in .htaccess. Send the request to a PHP script where you do the calculation then use the header function to do the redirect (not sure if you're using PHP, but the same principle applies to other languages).

in .htaccess:

RewriteEngine On
RewriteCond %{QUERY_STRING} id=([0-9]*)
RewriteRule page.php calc.php?id=%1 [L]

And in calc.php:

<?php    
$base_url = 'http://example.com/destination.php?id=';

if($_GET['id'] < 100){
    $new_id = 30;
}
elseif($_GET['id'] >= 100){
    $new_id = 40;
}

$url = $base_url.$new_id;

header("Location: $url"); 
exit();
bradym
id has different values,not only 100 .
hd