Reputation: 2742
I'm changing the structure of my pages and I need to re-direct the old ones to the new pages.
Here is an example of some of the following pages I need to move, basically anything in the pages
folder needs to be moved down, also the old pages always showed the php
extension.
www.example.com/pages/index.php www.example.com/index
www.example.com/pages/contact_us.php www.example.com/contact_us
Here is what I have so far
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteRule ^pages/(.*)$ /$1 [L,R=301]
Edit
the rewrite above works but makes pages such as example.com/contact_us unusable, you have to put an extension .php at the end, this is not a problem I had prior to this rule
Upvotes: 1
Views: 25
Reputation: 786319
You can use this code in your DOCUMENT_ROOT/.htaccess
file:
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \s/+pages/(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=302,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/pages/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ pages/$1.php [L]
Upvotes: 1