How to redirect in the secend time to correct path?
I want to save all query string adress url to data base which the user type in my domain , this work fine .
my problem is when htaccess redirect the user to root directory index.php/?parameter=query_string
I canot make the secend redirect to the target page request , there is some loop between the htaccess to root directory index.php
1. First I want to send the user to root directory by htaccess to save the query string.
2. then I want to check if the path is valid I want to send the user to his target page location.
Else I want that user will stay in the root directory.
Example if the user type
www.mydomain.com/folder1/subfolder
The first step will be like :
www.mydomain.com/index.php/?url=folder1/subfolder
Save query string "folder1/subfolder" to data base
The secend step will be redirect to location page which not working :
www.mydomain.com/folder1/subfolder
My htaccess code :
RewriteEngine on
Rewritecond %{HTTP_HOST} !^www\.kidslearning4fun\.com
RewriteRule (.*) //www.kidslearning4fun.com/$1 [R=301,L]
RewriteRule \.(sql)$ - [F]
RewriteRule \.(txt)$ - [F]
RewriteRule \.(zip)$ - [F]
RewriteRule \.(rar)$ - [F]
<IfModule mod_rewrite.c>
# For security reasons, Option followsymlinks cannot be overridden.
# Options +FollowSymLinks
Options +SymLinksIfOwnerMatch
Options -Indexes
RewriteEngine On
RewriteCond %{http_host} ^kidslearning4fun.com [NC]
RewriteRule ^(.*)$ http://www.kidslearning4fun.com/$1 [R=301,NC]
RewriteRule ^([^\.]+)$ index.php?url=$1 [QSA,L,NE]
</IfModule>
RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L,NE]
my root directory index.php :
<?php
if ($_GET['url']!= "") {
// url not empty there is query string
$url = $_GET['url'];
$url = rtrim($url, '/');
//echo ($url.'<br />');
$url = explode('/', $url);
$file = $url[0];
//print_r($url);
function save() {
//save the url to data base
}
if ($url[0] == 'folder1'){
//echo ('url = folder1<br />');
$path = $url[0];
//the path exists do redirect to folder1/index.php
//echo $path ;
header( 'Location: http://www.kidslearning4fun.com/folder1') ;
}
if ($url[0] == 'folder2'){
//echo ('url = folder2<br />');
$path = $url[0];
//the path exists do redirect to folder2/index.php
//echo $path ;
header( 'Location: http://www.kidslearning4fun.com/folder2') ;
}
}
else // url empty it is root directory
{echo ('<br /> url empty you are in the root directory<br />');
}
?>
I will glad to get any help, to log all the query string before redirect the user to his page request.
Many thanks.











