How do I use .RHTML (Ruby Included HTML) Files ?

The .rhtml is an extention for Ruby included in HTML


The default extention for ruby is .rb

If you would like to use .rhtml without deleoping a full Ruby on Rails application...

.htaccess

RewriteEngine Off Options +FollowSymLinks +ExecCGI AddHandler rubypage .rhtml Action rubypage /cgi-bin/erb.cgi DirectoryIndex index.rhtml index.html index.htm 

upload the .htaccess to the root folder of your "application"



erb.cgi

#!/usr/local/bin/ruby require 'time' require 'erb' include ERB::Util  time = Time.now.httpdate  HEADERS = <<-EOF Date: #{ time } Server: #{ ENV['SERVER_SOFTWARE'] } Last-Modified: #{ time } Content-Type: text/html  EOF  begin  path = nil if (ENV['PATH_TRANSLATED']) path = ENV['PATH_TRANSLATED'] else file_path = ENV['REDIRECT_URL'].include?(File.basename(__FILE__)) ? ENV['SCRIPT_URL'] : ENV['REDIRECT_URL'] path = File.expand_path(ENV['DOCUMENT_ROOT'] + '/' + file_path) raise "Attempt to access invalid path: #{path}" unless path.index(ENV['DOCUMENT_ROOT']) == 0 end erb = File.open(path) { |f| ERB.new(f.read) } print HEADERS + erb.result(binding)  rescue Exception  print "Content-Type: text/html\n\n"  # what the customer sees print "<h1>Page Not Found</h1>"  # modify message variables ENV['SERVER_ADMIN'] = "admin@yourdomain.com"  # email message MESSAGE = " From: Erb <admin@yourdomain.com> To: You <you@yourdomain.com> Subject: Error on YourDomain.com  ****Script Error**** #{ $! }  ****Backtrace**** #{$!.backtrace.join("\n")}  ****Environment**** #{ENV.keys.map { |key| key + ' = ' + ENV[key] + "\n"} }"  # send the message require "net/smtp" Net::SMTP.start('localhost', 25, 'yourdomain.com', 'admin+yourdomain.com', 'yourPassword', :login) do |smtp| smtp.send_message MESSAGE, 'admin@yourdomain.com', 'you@yourdomain.com' end  end 

upload the erb.cgi to the ./cgi-bin/ folder of your "application"
chmod permissions of erb.cgi to 755

If you want to use a .rhtml page for your 404 errors, add to the .htaccess file:

ErrorDocument 404 /404.rhtml 
  • 2 Benutzer fanden dies hilfreich
War diese Antwort hilfreich?

Verwandte Artikel

May I upgrade at a later time?

Yes, you can easily upgrade your account at anytime. Simply click "upgrade" in the Client Portal...

How soon can my account be setup ?

For shared hosting services, our system will automatically activate your account and send you...

How do I backup and restore my Website and databases ? How do I move my sites from my current host to Astutium?

If your old host is also using WHM/CPanel then there is a reasonably simple procedure to move...

How do I use SSI (server Side Includes) ?

Web pages that use SSI (server side includes) by convention should be named with the .shtml file...

How Do I Create a RoR (Ruby on Rails) Application ?

To make your first RoR (Ruby on Rails) application in your Astutium Business, ECommerce or...

Powered by WHMCompleteSolution