Jump to content
Larry Ullman's Book Forums
pablowerk

Relative Paths And Define Base_Uri / Base_Url Problem

Recommended Posts

I have been reading through all the URI based posts but I still can’t get the Coffee site example working on my local machine. I have my site located here: C:\apache\htdocs\eCom01\

I have the following setup in my config.php file:

define('BASE_URI','C:/apache/htdocs/eCom01/');
define('BASE_URL','http://localhost:8080/ecom01/');
define('MYSQL','includes/mysql.inc.php');

 

When I view http://localhost:8080/ecom01/shop.php all images display and data is being pulled from the database. Here’s what the relative links look on this shop.php file:

require('./includes/config.php');
include('./includes/header.html');
require(MYSQL);

 

Inside my header.html file I have tried to setup the links 2 different ways:

<li><a href="/shop/coffee/">Coffee</a></li>
<li><a href="./shop/goodies/">Goodies</a></li>

 

When I click the Coffee link, I get a NOT FOUND error

(The requested URL /shop/coffee/ was not found on this server.)

Somehow it is dropping the “/eCom01/” folder…

 

When I click the Goodies link, the page displays all the content from the database, but does not display the css file or any of the pictures.

 

I have been trying to trouble shoot this, but cannot come up with a fix. I have tried defining the BASE_URI and BASE_URL to many different values, but no matter what I set those to, I get the same results. I also added an

echo $_SERVER['DOCUMENT_ROOT'] ;

command on the shop.php file. This always displays “C:/apache/htdocs”

 

I am assuming this issue has something to do with setting the BASE_URI and URL items, but I can’t figure it out. Even if I comment out those 2 lines, the mySql connection still works. Is there some setting I have change in my apache configuration file to allow these changes? When I change these URI and URL variables, shouldn’t the

$_SERVER[‘DOCUMENT_ROOT’]

reflect them?

 

Any and all help is appreciated.

Share this post


Link to post
Share on other sites

What is the /shop folder i don't see that on the coffee setup? Ive got admin / images / includes / uploads. Your base URI and URL are correct you could change

 

define('MYSQL','includes/mysql.inc.php');

to

 

define('MYSQL','./includes/mysql.inc.php');

 

if you want to tidy up.

Share this post


Link to post
Share on other sites

The /shop/ folder is a virtual folder and with the following mod_rewrite, navigates the requests to the shop.php file.

 

<IfModule mod_rewrite.c>
RewriteEngine on
# For sales:
RewriteRule ^shop/sales/?$ sales.php
# For the primary categories:
RewriteRule ^shop/([A-Za-z\+]+)/?$ shop.php?type=$1
# For specific products:
RewriteRule ^browse/([A-Za-z\+\-]+)/([A-Za-z\+\-]+)/([0-9]+)$ browse.php?type=$1&category=$2&id=$3
# For HTTPS pages:
RewriteCond %{HTTPS} off
RewriteRule ^(checkout\.php|billing\.php|final\.php|admin/(.*))$ https://%{HTTP_HOST}/$1 [R=301,L]
</IfModule>

Share this post


Link to post
Share on other sites

Okay i get you, did you check that the mod rewrites are working? It could be a mod rewrite problem. Check that the .htaccess file is of file type htaccess and not just of type file.

Share this post


Link to post
Share on other sites

I have never used the computers directory structures when working with a site, not even localhost. I believe the base uri should be set according to the base path for the document root of apache, not your computer. This folder is the htdocs folder.

 

Try setting it according to that. That's my uneducated guess.

 

Also note that these are simple constants, not system affecting constants used by apache/PHP. The server global array constants won't be affected by your changes. Thats why the server document root is not changing.

  • Upvote 1

Share this post


Link to post
Share on other sites

@Edward, the mod rewrites are working. By going to http://localhost:8080/ecom01/shop/coffee/ the page does display the content from the database, the includes/header.html, and includes/footer.html files.

 

The problem is that all the relative links for the css, images, and page links, do not resolve/show.

 

@Antonio Conte, I am not exactly following you. I did try changing my BASE_URI and BASE_URL values, but I don't see those values affecting anything. According to the book, the includes/header.html file doesn't reference those vars anywhere? For example the css link is:

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

and not something like:

<link href="<?php echo BASE_URI ?>/css/style.css" rel="stylesheet" type="text/css" />

Share this post


Link to post
Share on other sites

Ok. If you don't utilize the constants, it will of course don't affect anything.

 

The easiest way to debug CSS/JS, is to click on the links when viewing the source code. You can then see when the script is looking for the scripts. It will get you a better understanding on how to fix the issue.

 

Besides that, I don't really have any advice for you.

Share this post


Link to post
Share on other sites

If you put your site in the ecom01 folder, then all your URLs and references must begin with ecom01. This includes HTML links, references to your CSS, and your .htaccess file.

  • Upvote 1

Share this post


Link to post
Share on other sites

how can I find out mod rewrite problem? when I click on goodies then it is showing following error-

 

 

Not Found

 

The requested URL /ex2/shop/goodies/ was not found on this server.

 

thanks

Share this post


Link to post
Share on other sites

Since your site is in the eCom01 directory, your absolute references in your HTML (and you have to use absolute references) have to begin with eCom01. Your mod_rewrite rules have to start with this, too, or use the RewriteBase directive.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

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

Loading...

×
×
  • Create New...