Tuesday, 16 June 2015

Redirect internal links to another file with .htaccess

Redirect internal links to another file with .htaccess


Requirement:
When someone open http://domain.com/projectone.html, User should be able to see the same URL in Browser(i.e. http://domain.com/projectone.html). But Internally, application should call a file http://domain.com/projectone.php. But user should not get to know this.

Solution:
This is 100% achievable by .htaccess in single line.
But your application must allow and support the .htaccess.
RewriteEngine On
RewriteRule ^(projectone\.html)$  projectone.php [R=301,NC,L]


Following are the means of htacess flag used above.
R 301- means permanent redirect.
NC- means this rule is case -insensitive.
L- mens stop processing to next set, if the rule matches, no further rules will be processed.