Jump to content

Recommended Posts

Posted

I'm interested in converting my MT3.2 blog output files from html to php, and since the blog is old (2+ yrs) and med. sized (2k posts), there are a lot of links, internal and on the web, to individual posts that I'd like to maintain.

 

From what I understand, apache's mod_rewrite can do this, and dynamically rewrite an incoming URL request to change the .html extension to .php (which, I think, is all that I'll need, since the archive structure isn't changing.)

 

1) Is mod_rewrite something I have to request to be activated/installed on my (shared/reseller) server?

2) where is it, and where's .htacess, which I apparently need to edit?

3) a SixApart forum on converting MT to PHP [link here] includes this script:

 

RedirectMatch (.*)\.shtml$ http://greengabbro.net$1.php

 

which, if I understand correctly, should be altered to this, since my extensions are .html, not .shtml. Right?

RedirectMatch (.*)\.html$ http://mysite.com$1.php

 

does it matter that there's no www? I usually don't use it, but a lot of site readers/linkers do.

 

thanks in advance,

 

oh, and 4) Ideally, to catch dead links or links that have changed more than just *.php, I'd like to add something to my customized 404 page that parses an incoming URL and present links to both/either a close-matching URL or a related search result. I think this'd come a lot from google images searches, for example, where the referring url has google search terms in it, but where I'd like to serve up the image in context, not just hand it over raw/alone. Or is this another topic altogether?

Posted

1. mod_rewrite is installed on all servers

 

2. You need to edit the .htaccess file in your blog root directory. If all you have is a blog and it resides in the public_html folder that's the one to edit. If you don't have one you need to create one. Before your rewrite statements you use RewriteEngine On to turn the mod_rewrite on.

 

3. If your pages end in .html then yes you would use the second statement.

 

4. Not sure how to accomplish this but you can create a custom 404 page.

Posted

1. Yes, mod_rewrite is active on all accounts

2. .htaccess will be in the public_html directory. Please note that by editing it, you can mess up your account - so be prepared to remove the changes again ;)

 

3.

 

I'd try something like

>#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   ^(.*)$ $1.php			 [R=301,S=1]
#   else reverse the previous basename cutout
RewriteCond   %{ENV:WasHTM}			^yes$
RewriteRule   ^(.*)$ $1.html

 

This will check if the file and see if a relevant php file exits. If it doesn't it will return to the original file name, this is where you would do part 4 - giving it something more useful ...

Posted
1. Yes, mod_rewrite is active on all accounts

2. .htaccess will be in the public_html directory. Please note that by editing it, you can mess up your account - so be prepared to remove the changes again ;)

 

Sweet, thanks.

 

I think for now, I'll stick with the one line that makes sense, and just add a searchbox to my 404 page while I look around for an example of a site that does what I'm imagining. crawl walk run, etc.

 

of course the "you can mess up your account" reminder has nothing to do it :P

Posted

hm, so will it be ok if all my .htaccess has in it is:

 

#RewriteEngine on

RedirectMatch (.*)\.html$ http://mysite.com$1.php

 

Or is there a bunch of default stuff you need to cover in an .htaccess file IF you're going to have one? [none of the .htaccess documentation I've seen on the web discusses these big, existential questions...]

Posted

remove the hash (#) from infront of the RewriteEngine - as that is turning it into a comment.

 

As long as you are not using FrontPage (which does need stuff in the .htaccess) then you can have one that is blank, or has just the commands above, yes.

Posted

Hmm. So far, the only thing that I'm seeing is that, yes, I can screw up my account with an .htaccess file.

 

I've tried creating files with both sets of commands above [as is, except I removed the # on the RewriteEngine On line] which textedit sees as rtf files, but which I place as text using ftp and name ., no extension, and which show up as 'documents'.

 

after refreshing the ftp window, the file doesn't show up, but as long as it's there, I get 500 error messages trying to load any pages or click through to any php or html links. The error msg also says there was an error loading the error document, which I interpret as a problem loading the 404.shtml page, the only html-formatted page on the site at the moment.

 

If I replace .htaccess with a blank file, then delete it from my ftp window while I can still see it, everything's back to normal [i.e., all my files converted fine to php, but no redirect/rewrites and thousands of dead links.]

 

Is there something in my .htaccess creation or uploading process that's just plain wrong? Or is there something in my settings/site that I should open a ticket for?

 

thanks,

Posted

The file is a text file and the best way to create and access it is with File Manager through cpanel.

 

You are correct that files beginning with a period do not appear in an FTP client unless you turn on the option to display hidden files.

Posted

thanks, I figured as long as the process was general and possibly future-relevant for others, I'd keep asking here. If I have specific problems with my server, I'll take'em to the help desk.

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...