Wednesday, 9 November 2016

Redirect request using htaccess without changing the browser url

It's very simple if you know what's happening behind the line.

Lets see the requirement first, we have a url www.example.com/product/product1-page
Lets and we want to forward request to www.example.com/product?page=product1

Simply create a htaccess file under "PRODUCT" directory and copy below two lines

RewriteEngine on
RewriteRule ^/?(.*)-page ?page=$1 [L]

Explanation

^  - start matching request from here
(.*) - will become our variable $1
-page - request ending with -page
[L] - make this last rule


Once done, you can see the browser will show URL as www.example.com/product/product1-page

but underline request will to www.example.com/product?page=product1




No comments:

Post a Comment