user3851100
user3851100

Reputation: 3

301 redirect using .htaccess for a php file

We had a website redesign and some of the pages no longer exist. I did 301 redirects on most of the old pages, but rather than have all of those old pages still in my folders I wanted to redirect everything in the .htaccess file instead. Below is my whole .htaccess file as of right now. The redirect of an html file to a php file works fine, but trying to redirect from a php file to a php file is not working. I have tried leaving the first part of the url (up to the .com) off of the new page but I still get a 404 error. I have tried multiple other pages and get the same results every time, directing from html to php works but from php to php doesn't. Any suggestions?

Options +FollowSymLinks
RewriteEngine on
Redirect 301 /folder1/page1.php http://www.example.com/folder2/page2.php
Redirect 301 /folder1/page1.html http://www.example.com/folder2/page2.php

Upvotes: 0

Views: 699

Answers (1)

James
James

Reputation: 860

RewriteEngine On
RedirectMatch 301 folder1/(.*) folder2/$1
RewriteRule ^(.*)\.html$ $1.php [L]

Edit:

RedirectMatch takes everything in folder1 and redirects to folder2

RewriteRule then takes all html file extensions and rewrites them to php

Upvotes: 1

Related Questions