Jump to content

Recommended Posts

Posted

Hi -

 

I just got my account set up, and I have FTP'd my index.shtml page up with the rest of the required files in the root directory.

 

I can view the page at http://xx.x.xxx.xxx/~username/

But, I am having a small problem with the include virtual:

 

<!--#include virtual="/header.html" -->

 

Which is used all through my site, and works OK on the current host. (I get the [an error occurred while processing this directive] error) I expected to have some problems after searching around here and seeing similar comments. However, I didn't see any solutions (even short term for testing). If I change the code to:

 

<!--#include virtual="/~username/header.html" -->

 

then it works OK. However, I don't want to make these changes to test the site, because it's not really a valid way to make sure everything works OK! Similarly, the CSS file is not getting picked up

 

<link rel="stylesheet" type="text/css" href="/mycss.css">

 

For the same reason.

 

Question: Is there any quick setting I can put in a .htaccess file in public_html to temporarily set the document root to http://xx.x.xxx.xxx/~username/ ??? Or some other method???

 

Thanks

Posted

Until your domain is propogated you have to use /~username in the path, because / points to the ip's root, not your site root.

 

Once the domain is propogated, it'll work. As far as I know, there isn't a way around this.

Posted

Thanks for your quick reply. I think it probably will be OK.

 

Since I have you on the line, there is one more question: I use some .htaccess files to prohibit directory browsing, etc such as

 

>Options -Indexes

 

I can FTP them to my site using WS_FTP, but for some reason I can't see the files any longer. Is this some limitation of WS_FTP, or some setting? I can see them with cpanel OK though.

 

Thanks for any help on this -

Posted

:eek: Welcome to the Family :)

 

and your new home!

 

For the include

<!--#include virtual="/header.html" -->

 

if the header is in the same folder you might try

 

<!--#include virtual="header.html" -->

with out the leading /

 

You also may want to check out using php includes sometime.

You may find php more flexiable, such as passing data to the included file.

Like adding additional custom text to the title for each page.

Example: in the content page, you put this at the top

 

<?php

// add header and additional title

$page_title="about";

include $_SERVER['DOCUMENT_ROOT']."/header.php";

// begin main content

?>

 

then the header can display the title like this

 

My site <?php print("$page_title"); ?>

 

anyway, something to consider.

 

 

We really are like family here.

So if you need anything,

just ask your new family!

We love to help :)

Posted

If you really want your site to look the same whether accessed through your domain or your IP address, you can accomplish it with some PHP code. You'll have to either change the file extension of your .html files to .php, or change .htaccess so that PHP inside .html files will be parsed. (Off the top of my head I'm not sure what needs to go in .htaccess for this, but someone more familiar with .htaccess than me must be reading. :eek:)

 

One easy thing you can do is to use PHP's include statement instead of server-side includes. PHP include takes a system path instead of a URL so your problem is sidestepped. So

><!-- include virtual="/header.html" -->

becomes

><? include "/home/username/public_html/header.html"; ?>

 

(It may be possible to do the same thing in a server-side include, and I just don't know how.)

 

Making all of your HTML tags work, not just includes, is a little trickier. On my site, I use a hack like this to detect whether the site is being accessed via the domain name or the IP address / server name:

><?
$base_dir = dirname($_SERVER['PHP_SELF']);
if (strstr($base_dir, "~username") == FALSE)
   $base_dir = "";    
else
   $base_dir = "/~username";
?>

 

For convenience, you can put the above code in a separate file (say, global.php) and then include it at the beginning of all your HTML files like this:

><? include "/home/username/public_html/global.php"; ?>

 

Then, anywhere in your HTML files that you want to refer to the root of your site, use the string <?=$base_dir?>. So

><link rel="stylesheet" type="text/css" href="/mycss.css">

becomes

><link rel="stylesheet" type="text/css" href="<?=$base_dir?>/mycss.css">

 

It's a little rough around the edges, but it works, and it's something you can use even if you don't necessarily understand what all the PHP does yet.

 

Good luck with your site!

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