Forum Moderators: coopster
for eg mydomain.com/loans.html would show mydomain.com/s.php3?term=loans
how do i pass the variable 'term' in the .htaccess.
anyone can add a few php codes to pass the term variable.
ErrorDocument 404 /s.php3?term=
/loans.html
/loans.htm
/loans/
/loans
...would all redirect to /s.php3?term=loans
However,
/loans.html?
/loans?
...would redirect to /s.php3?term=loans.html? and /s.php3?term=loans? respectively.
Let us know if you need any additional matching...
to this:
$uri = preg_replace("/^\/¦[^a-zA-Z0-9].*/","",$uri);
Then it will strip the first non-alphanumeric character, and all following characters.
So,
/loans
/loans.html
/loans/
/loans.lkajshd ,.asdfkl;aj sdjas.fjk
...will all redirect to /s.php3?term=loans :)
Note: The pipe ¦ should not be broken, so you need to replace them manually
will my .htaccess look like this
ErrorDocument 404 <?php
$uri = $_SERVER['REQUEST_URI'];
$uri = urldecode($uri);
$uri = preg_replace("/ +/"," ",$uri);
$uri = trim($uri);
$uri = preg_replace("/^\/¦\/$¦\.(htm[l]?)/","",$uri);
header("Location: /s.php3?term=$uri");
?>
DirectoryIndex index.php3
<Limit GET>
order allow,deny
allow from all
</Limit>
ErrorDocument 404 /s.php3
... and put this code first in your s.php3 file:
<?php
$uri = $_SERVER['REQUEST_URI'];
$uri = urldecode($uri);
$uri = preg_replace("/ +/"," ",$uri);
$uri = trim($uri);
$uri = preg_replace("/^\/¦[^a-zA-Z0-9].*/","",$uri);
$term = $uri;
?>
However, this could cause problems if your s.php3 file is ever accessed directly. If it only handles error requests, then it should be ok.
site.com/loans.html goes to site.com/s.php3?term=/loans.html
instead of going /s.php3?term=loans
something wrong in the php code?
$uri = preg_replace("/[^a-zA-Z0-9].*$/","",$uri);
with:
$uri = preg_replace("/[^a-zA-Z0-9_].*$/","",$uri);
$uri = preg_replace("/_/","+",$uri);
Note that you don't need to pass the _ as a plus. You can replace the + in the above function with just a space. The variable would then be "free loans" instead of "free+loans". No urldecoding will be performed in s.php3 since the file is included