Reputation: 787
I'm working on rebuilding a link structure of a site.
For some parts the site now respond with actual php script like:
DOMAIN/about-us.php
I have to remap those kind of URLs like so (this is just an example):
DOMAIN/about-us.php --> DOMAIN/uk/about-us
Since those pages have been already indexed I'd like to use 301 redirects to the new resources.
I used those kind of rules:
RewriteRule ^/about-us.php$ /uk/company/about-us [R=301,L]
RewriteRule ^/uk/company/about-us$ about-us.php [L]
but this hit an infinite loop.
I tried different solutions with no luck (I tried also this one: How to stop .htaccess loop - the second method suggested). The only thing that worked in my environment was to rename about-us.php and update the rule. But since we have a lot of scripts renaming all of those is not an optimal option.
Upvotes: 2
Views: 1590
Reputation: 19528
Give this a try:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.*)\.php [NC]
RewriteRule ^ /%1 [R=301,QSA,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f
RewriteRule /?([^/]+)/?$ $1.php [L]
Will work only for the php's on the root folder.
Upvotes: 2