arvind Posted September 19, 2003 Posted September 19, 2003 Ok I'm using movable type and had generated quite a few individual archives over the course of my blogging. But after I skinned my site I switched all the archives from .html extensions to .php extentions. Is there some way to redirect all these .html extention to the same file name but with a .html extention ? ie my /blog/archives/00001.html ----> /blog/archives/00001.php ? I have over 100 pages and don't want to input one line for eahc of them in my .htaccess Quote
TCH-Andy Posted September 19, 2003 Posted September 19, 2003 (edited) Hi, I use a quick check to see if the htm code exists - if not then redirect to the php file if it exists >RewriteEngine on RewriteBase / # parse out basename, but remember the fact RewriteRule ^(.*)\.htm$ $1 [NC,E=WasHTM:yes] # rewrite to document.php if exists RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^(.*)$ $1.php [R=301,S=1] # else reverse the previous basename cutout RewriteCond %{ENV:WasHTM} ^yes$ RewriteRule ^(.*)$ $1.htm Andy Edited September 19, 2003 by AndyB Quote
arvind Posted September 19, 2003 Author Posted September 19, 2003 Ok I put that code into y .htaccess but it doens't work I went to http://blog.arvind-satya.com/archives/000017.html which doesn't exist anymore and I want to redirect thaat to http://blog.arvind-satya.com/archives/000017.php ! Which it didn't ! I think somewhere I'm pointing to the wrong path can you just gimme the code where I want to point it to my /home/USERNAME/public_html/blog/archives/ directory ? cos all my files are there ! Thumbs Up Quote
TCH-Andy Posted September 19, 2003 Posted September 19, 2003 Sorry, I'll go back one step. All redirects should be done in the .htaccess file. You can edit it from the file manager in cPanel. Have a look at our Tutorials on .htaccess for how to perform redirects. Quote
arvind Posted September 19, 2003 Author Posted September 19, 2003 So i have no choice I have to put an individual redirect for each file ? UUuugh !! Quote
TCH-Andy Posted September 19, 2003 Posted September 19, 2003 (edited) No. The code I provided looks at the request someone has made. If it ends in .htm it checks if the file exists, if it does not, and a file of the same name with a .php extension exists it redirects to that. ie. If you put the code I provided in your .htaccess, and renamed all your files from .htm to .php, then it will work. since you were using html not htm, then change the .htm in the code I provided to .html Andy Edited September 19, 2003 by AndyB Quote
arvind Posted September 19, 2003 Author Posted September 19, 2003 (edited) Thanks for the quick replies but I must be really stupid because it ain't working. What am i doing wrong here's the code I put in my .htaccess >#RewriteEngine on RewriteBase / # parse out basename, but remember the fact RewriteRule ^(.*)\.html$ $1 [NC,E=WasHTM:yes] # rewrite to document.php if exists RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^(.*)$ $.php [R=301,S=1] # else reverse the previous basename cutout RewriteCond %{ENV:WasHTM} ^yes$ RewriteRule ^(.*)$ $.html the only thing is the files are located in /blog/archives/ ! What am i doing wrong :'( Oh i just remembered that those files no longer exist. Do I still have to have them in my folder for this to work. I deleted them because they were cluttering it all up ! edit: Ok i just re-created all my html files in case that was the problem but no it still doesn't work ! Mad!!! Edited September 19, 2003 by arvind2100 Quote
TCH-Andy Posted September 19, 2003 Posted September 19, 2003 PM me and I'll have a look at the files for you. Andy Quote
arvind Posted September 19, 2003 Author Posted September 19, 2003 have done & thanks ! Thumbs Up Quote
TCH-Andy Posted September 19, 2003 Posted September 19, 2003 Hi, My fault, sorry - there was a # in my example at the start of the code, which should not have been there. It should all be working now, and I have corrected my code above if others want to use it. Andy Quote
TCH-Andy Posted September 19, 2003 Posted September 19, 2003 The issue was corrected, If you are using a subdomain, then you need to modify the RewriteBase. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.