Jump to content


Photo

How to redirect to any path ?

htaccess redirect

  • Please log in to reply
4 replies to this topic

#1 ancit

ancit

    Member

  • Members
  • PipPip
  • 10 posts

Posted 17 December 2012 - 01:10 PM

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.

 

 


#2 jream

jream

    Administrator

  • Administrators
  • 52 posts

Posted 18 December 2012 - 10:59 PM

Thanks!



#3 dlantz

dlantz

    Newbie

  • Members
  • Pip
  • 7 posts

Posted 20 December 2012 - 03:23 PM

this is excellent. thanks for sharing.



#4 dlantz

dlantz

    Newbie

  • Members
  • Pip
  • 7 posts

Posted 21 December 2012 - 04:15 PM

haven't figured this out yet. 

 

did you find a resolution? 



#5 ancit

ancit

    Member

  • Members
  • PipPip
  • 10 posts

Posted 22 December 2012 - 09:23 PM

My english is not well.

 

No I don't have any solution I stuck .

I'll appreciate for any help.

Thanks

 





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users