Jump to content

Adding predefined text to webpage


mandude

Recommended Posts

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/subfolder/hi that it will put "hi" in the page where I want.

 

The code I had was something like:

 

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

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

 

 

then in the page it would have

 

<?=$item2;?>

but I cant get it to work. help please!

Link to comment
Share on other sites

When you say what you tried hasn't worked, what have you tried? You didn't mention anything about htaccess, which is what would solve this problem, since it is relating a special url with what is displayed on the page. You would put this code in your htaccess file. This code probably isn't exact, but it's the right idea

 

RewriteEngine On

RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ specialpage.php?variable=$2 [NC]

Link to comment
Share on other sites

Just tried it, it did not work. will just say URL not found.

Here is the htaccess file I had:

 

Options +FollowSymLinks +Indexes
RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^.]+)/([^.]+)$ index.php?item=$1&query=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^.]+)$ index.php?item=$1 [L]

# AddHandler application/x-httpd-php .php .htm .html

RewriteEngine on
# RewriteBase /offers
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [s=44]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [s=44]
RewriteRule ^(.*)$ index.php?k=$1&%{QUERY_STRING}

Link to comment
Share on other sites

Ok so like I said I dont know squat about coding. But I can see that if I put something like www.mysite.com/subfolder/index.php?item=something that "something" will be replaced in the document because item was defined (and in the index.php it tells it to replace item with item2 which is in the document)

 

So I just have to figure out how to make the site know that anything after the /subfolder/ is the item. so mysite.com/subfolder/something that "something" is the item.

 

Maybe that makes things clearer (maybe you already knew that)

but I am not good with .htaccess files

 

thanks again

Link to comment
Share on other sites

I figured it out!

 

So I put this in the htaccess

 

Options +FollowSymLinks +Indexes
RewriteEngine on
RewriteBase /offers

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^]+)/([^]+)$ index.php?item=$1&query=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^.]+)$ index.php?item=$1 [L]

# AddHandler application/x-httpd-php .php .htm .html

 

subdomain was offers. I put that in that subdirectory (seems weird that I defined the directory but still had to put it in the directory) and now it works :)

 

can be locked. this thread may be useful for others later

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

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

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

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

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.