Jump to content
Larry Ullman's Book Forums

Problem With My Base_Url In The Config File


Recommended Posts

Hello,

I am enjoying the book Larry, and am very excited about having purchased it.

 

I have just started the 2nd example and have already hit a snag.  :(

 

I created a folder called 'ECOM_2' to hold all of the files, and I'm using MAMP to develop locally.

Here are my constants as I have them in the config file for URI and URL,

 

define ('BASE_URI', '/Users/myname/Desktop/Main-Folders/LOCAL_SITES/ECOM_2/');
define ('BASE_URL', 'localhost:8888/ECOM_2/');

 

... with those setting, the css link is broken, and all links seem to broken... so I'm assuming that I have typed in the BASE_URL setting incorrectly.

 

Could anyone shed some light on this for me?  thanks so much,

 

 

 

Link to comment
Share on other sites

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

That is what the link to the css file looks like - exactly out of the EXAMPLE #2 - in the header.html (which is in the includes folder)

 

I took all of the files inside of the "html" folder from the downloaded code, and placed it in my folder called "ECOM_2" which holds all of the files for this example on my local server.

 

Here is one of the links from the nav...

<li><a href="/cart.php"><img alt="" src="/images/icon-cart.gif" /></a></li>

again.... straight from the header.html file which I downloaded from Larry's code.

 

When I hover over these links to see where they are sending me... it shows the following structure

localhost:8888/cart.php 

... so it is missing the ECOM_2 folder for some reason...

 

yes I do believe I have the mod_rewrite on, as I believe it is enabled in the .htaccess file, exactly as in the example... I didn't change any of that.

 

hmmm......  thanks for responding !!!  :)

Link to comment
Share on other sites

answer to your 1st question... apologies...

 

the css file is within the css folder

 

the file that links to it (header.html) is within the includes folder

 

the includes folder and css folder are both on the same level (within the ECOM_2 folder, which holds everything for the site... I don't know how to place folders on the same level as the root directory with GoDaddy... that is why I am doing it this way)

Link to comment
Share on other sites

More than likely, mod_rewrite is "messing" everything up.

The thing about mod_rewrite is that even though the server is in on the "gig" and knows how the URLs are being rerouted, the client (i.e., the browser) does not.

 

As such, in order to get the browser to not look for nonexistent files in nonexistent folders, you need to do one of two things for any CSS/JS files you're linking to:

1) Use the HTML base element.

2) Specify absolute paths.

 

I generally recommend option #2, but you can go with whatever works.

 

As a quick test, try changing your CSS link element to the following and see if it works:

<link href="http://localhost/ECOM_2/css/style.css" rel="stylesheet" />

Please let me know what you find.

Thank you.

Link to comment
Share on other sites

Yeah, using the absolute path definitely works.  Although I just had to add the

:8888

part to your css file link, just to be clear for anyone else reading... but yeah that worked...

 

I just figured that as this example goes on, that hard coding the links would be a problem... but I don't know... ???  :unsure:

 

 

EDIT: and also, when I go live, it seems that I would have to change a ton of hardcoded links too... 

Link to comment
Share on other sites

Well, yeah, you don't want to hard-code all the links.

I asked you to do that just for testing purposes.

If you are using mod_rewrite and an absolute link works, but a relative one does not, then my recommendations before still hold.

 

I would recommend adding "aitch-tee-tee-pee-colon-slash-slash" (http://wiki.answers.com/Q/How_do_you_spell_the_letters_of_the_alphabet) to your BASE_URL constant, and then using that constant at the beginning of all links to CSS/JS files.

 

That's an easy solution that can easily adapt to any changes to your server/environment.

 

Edit: I had to spell out the protocol above because some auto-filter on this forum was removing that line of text otherwise.

Link to comment
Share on other sites

 Share

×
×
  • Create New...