Jump to content

Recommended Posts

Hi all

 

My site is build using php includes. the index.php file contains code like

<?php

if(@$_GET['page'] == "web-design"){

include("includes/web-design.php");

} else if(@$_GET['page'] == "hosting"){

include("includes/hosting.php");

}

else {

include("includes/home.php");

}

?>

 

I have created a sub domain blog.maplewebdesign.co.uk and a sub dircetory named blog. The link to this part of my site doesn't use includes, I want it to link directly to that sub directories index.php page.

This works fine, but then when I click on a different link anywhere on the site my url is as follows

www.maplewebdesign.co.uk/blog/index.php?page=home

 

For some reason it is keeping the blog/ in the URL

 

If you want to see go to

http://www.maplewebdesign.co.uk/blog/

then click on a differnt link and check out the URL

 

What am I doing wrong?

 

Thanks

Adi

Link to comment
https://forums.phpfreaks.com/topic/258825-url-incorrect-on-php-includes/
Share on other sites

visiting your site under http://www.maplewebdesign.co.uk/blog/, the site URI will retain /blog/, but when you visit under  http://www.maplewebdesign.co.uk/, your URI is preserved.

 

if you run apache, you can get rid of that uri segment with .htaccess

$_SERVER['DOCUMENT_ROOT'] contains the full path to the root of your webserver.  Use that in all your include() and require() statements so that regardless of how "Deep" you are in the folder structure, your includes will always go to the right file.

 

You don't need to mess with htaccess for this.

I can see what you mean, I've had a little play about but still to no avail.

 

In my index.php file i've done the following

 

<?php

if(@$_GET['page'] == "web-design"){

include($_SERVER['DOCUMENT_ROOT'].'/includes/web-design.php');

} else if(@$_GET['page'] == "hosting"){

include($_SERVER['DOCUMENT_ROOT'].'/includes/hosting.php');

}

else {

include($_SERVER['DOCUMENT_ROOT'].'/includes/home.php');

}

?>

Is this right?

 

Also Just to give you a little bit more info, my left nav comprises of the following:

 

<li class="home"><a href="index.php?page=home"><div class="text-hide">home</div></a></li>

<li class="web-design"><a href="index.php?page=web-design"><div class="text-hide">web design</div></a></li>

<li class="hosting"><a href="index.php?page=hosting"><div class="text-hide">hosting</div></a></li>

 

I've added the $_SERVER['DOCUMENT_ROOT'] into my index.php file but I'm still getting the same problem. the "blog/" part of the url is still there

 

Am I missing something

 

Thanks

1)  I don't know if your includes are right because only you can tell us that.  Print out the complete string you're including and see if it's pointing to the right file.  If so, it's right.

 

2)  Your links are all relative as well, you need to use your full domain or start your links with a /

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.