Search code examples
.htaccessurl-mapping

.htaccess capture the current url & take the url as query string to a page


I want to capture the url via .htaccess & send that url as a query string to the page which will check the existence of the url from the DB.

So my problem is i have a old site with www.example.org & this has 4200 old links that should be mapped with the new site www.example.net.

Now i have created a url mapper app which has the old site urls (4200) mapped with the new one. In this url mapper app, i have an .htaccess which will capture the url before sending it to the app. Now here i want to capture the complete URL hit by the user which points to the old site & then the url is sent to one page with query string as complete url, which can be checked against the (4200) old urls & then redirected to the corresponding page of new site.

How can i achieve this. To get the compelete URL in .htaccess & pass it to the page as request parameter.


Solution

  • RewriteEngine On
    RewriteCond %{REQUEST_URI} !^/mapping_script.php
    RewriteRule ^(.*)$ /mapping_script.php?url=http://%{HTTP_HOST}%{REQUEST_URI} [L,QSA]
    

    You'd replace mapping_script.php with whatever this script of yours is called. If you don't need the http://domain.name/ part of the URL, remove http://%{HTTP_HOST} from the rule's target.