Adding predefined text to webpage

mandude

Senior Member
Jr. VIP
Joined
Feb 18, 2008
Messages
1,106
Reaction score
455
Not sure if that title encapsulates what I am trying to say, but basically I have the script that can work if the page is on the root of the domain with htaccess, but not in a subfolder.

I just want an easy way to have it so if I type in a domain name such as: www.mysite.com/hi that it will put it in the page where I want.

The code I had was something like:

PHP:
$item = $_GET['item'];
if (!$item) $item = "test";

$item2 = str_replace("-", " ", $item);
then in the page it would have
PHP:
<?=$item2;?>

but I cant get it to work. help please!
 
So, If I understand you right, you have a file in your root folder you want to include in a subfolder?

foo.php (in your document root, wich could be /www/ or /public_html/)
PHP:
<?php
if(isset($_GET['item']) {
$item = $_GET['item']; }
  else {
$item = "test"; 
         }

$item2 = str_replace("-", " ", $item); 
?>

then in a subfolder called /hi/
PHP:
<?php
require_once($_SERVER['DOCUMENT_ROOT'] . "foo.php");
          
                  echo $item2;
?>
 
Last edited:
Well the thing is I don't want to use it on the root, because the root is a real website. But I want this function to work in a subfolder.
I guessed I messed up what I was trying to say with the /hi example. What it really would be is www.site.com/subfolder/hi
and then the page would reflect that with the word hi in the place of 'item'

I can get it to work on the root, but not in a subfolder.
 
If i would be able to understand what you mean, then i would help you.
You are testing GET parameter item, but in your url is nothing like that.

If you just want to use a script from your root, when the url directs to your subdomain, then the example that inviz provided is correct.
 
I figured it out, I used a .htaccess to get it to work. if anyone wants to know what i did i can post it, but my problem is solved!
 
Back
Top