regex – .htaccess 301 redirect from root folder to a subfolder with the same page name

I’m not familiar with htaccess and RegEx.

I want to remove the .php extension from about-us.php to about-us

And then 301 redirect from:

example.com/about-us

to:

example.com/company/about-us

I used below RewriteRule to remove the .php extension

RewriteRule ^about-us$ about-us.php [L]

But I cannot use the same pattern matching of ^about-us$ because there are two of ^about-us$ exists and below RewriteRule does not do the 301 redirect:

RewriteRule ^about-us$ https://example.com/company/about-us [R=301,NC,L]

Also, is there a general htaccess rule to remove the .php extension for all of the pages so about-us.php, contact-us.php becomes about-us, contact-us, etc..?

Read more here: Source link