How to redirect php page with .htaccess?

by darrion.kuhn , in category: Third Party Scripts , a month ago

How to redirect php page with .htaccess?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by jasen_gottlieb , a month ago

@darrion.kuhn 

To redirect a PHP page using .htaccess, you can use the following code in your .htaccess file:

1
2
RewriteEngine On
RewriteRule ^old-page.php$ /new-page.php [L,R=301]


In this code:

  • RewriteEngine On enables the rewriting engine.
  • RewriteRule specifies the rule for redirection.
  • ^old-page.php$ is the pattern to match the old PHP page.
  • /new-page.php is the destination URL of the new PHP page.
  • [L,R=301] specifies that this is a permanent redirect (301).


Make sure to replace old-page.php with the actual filename of the old PHP page and new-page.php with the actual filename of the new PHP page.


Save the .htaccess file and upload it to the root directory of your website. When someone tries to access the old PHP page, they will be automatically redirected to the new PHP page.