| 301 Redirect of .php files to html under sub-folder [message #931] |
Tue, 22 April 2008 11:15  |
shinerweb Messages: 2 Registered: April 2008 Location: UK |
|
|
|
I have a series of old .php files that exist under a sub-folder
/public_html/folder1/folder2/folder3/file1.php
/public_html/folder1/folder2/file2.php
/public_html/folder1/file2.php
I want to be able to 301 redirect those files to their .html equivalent.
/public_html/folder1/folder2/folder3/file1.html
/public_html/folder1/folder2/file2.html
/public_html/folder1/file2.html
Now I was thinking along the lines of
RedirectMatch 301 (.*)\.php$ http://www.example.com$1.html
But that doesn't work.
I'd rather have a rule that I can place in my top-level .htaccess, rather than have multiple .htaccess file dotted around, so I'm looking for a decent regex that would do this.
I could place a .htaccess in /public_html/folder1/ that would only effect that and any subsequent sub-folders to make it simpler, but I'm open to any suggestions.
I can't just redirect ALL php files to their html equivalent on the whole server. (Because I have some php files that I don't want 301' redirected).
But I have one sub-folder under which ALL php files can be 301 redirected.
Any help much appreciated.
Regards
Chris
|
|
|
| Re: 301 Redirect of .php files to html under sub-folder [message #932 is a reply to message #931 ] |
Tue, 22 April 2008 11:48  |
shinerweb Messages: 2 Registered: April 2008 Location: UK |
|
|
|
Why is that always after I make a post I get a blazing flash of inspiration and answer my own question about 2ms after hitting the post button.
The following works, if I place it in the sub-folder,
RewriteRule ^(.*)\.php$ /folder1/$1.html [R=301,L]
So although it's not my ideal solution (of creating an entry in my top-level .htaccess file, at least I have a working solution for my problem.
I guess I'll have to get my regex book out.
Chris
|
|
|