Redirect/Rewrite without changing address (.htaccess)

Viewed 32

I want to have a promo page as a temporary replacement for a main page.

mydomain.com/page.php to mydomain.com/page-promo.php

I already have a rewrite rule to convert html to php

# HTML to PHP
RewriteEngine On
RewriteRule ^(.*)\.html$ $1.php [L]

With the promo page, I want the URL in the user's address bar to remain mydomain.com/page.php and this whole thing needs to work if they use .php or .html (I think I just need to put the new rule after the html->php rule)

What syntax is used to prevent the URL address bar from showing the real (promo) address?

1 Answers

Have it like this:

RewriteEngine On

# assuming /page.php is just a single page
RewriteRule ^page\.php$ page-promo.php [L,NC]

RewriteRule ^(.+)\.html$ $1.php [L,NC]

However if /page.php can be any other page then use:

RewriteRule ^([\w-]+)\.php$ $1-promo.php [L,NC]
Related