Reputation: 453
I would like to redirect a url like example.com/contact/
to example.com/contact.php
without the visitor viewing the redirection. So, the browser should keep example.com/contact/
.
I know how to do simple redirect with .htaccess, but the problem is that I can't use absolute paths for different reasons so the page does not load correctly.
RewriteEngine on
RewriteRule ^contact/?$ contact.php [NC]
Any alternatives?
Upvotes: 0
Views: 182
Reputation: 755
I think this is an easier way using PHP:
<?php
//add some params
$_GET['param1'] = value1;
$_GET['param2'] = value2;
//the actual page you wish to redirect to
include "/var/www/page.php";
?>
Upvotes: 0
Reputation: 784918
You can use this additional rule:
RewriteRule ^[^/]+/(.+?\.(?:jpe?g|gif|bmp|png|ico|tiff|css|js))$ /$1 [L,NC,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^([^/]+)/?$ /$1.php [L]
Upvotes: 1