Jump to content

Recommended Posts

Posted

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

Posted (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 by AndyB
Posted
:unsure: 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
Posted (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 by AndyB
Posted (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 by arvind2100
Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...