mod_rewrite messing up Header/Stylesheets

I’m using MAMP on my MacBook.

So how do I do that? (Although I’ve already structured all of my other code to work with my config file - which works quite nicely!)

Debbie

Huh?

I re-coded them that way!

By doing so, I ensure that they are absolute paths pointing back to the Web Root.

That’s pretty straight-forward…

My problem now is between phpMyAdmin being a pain with single quotes and wanting to do this…

Current Code



<img src="images/some_image.jpg" width="150"
	 alt="Picture"
	 title="Picture" />
	<p>This is my article following here...</p>


I am now trying to store that in a “MediumText” field in MySQL.

I attempt to print it by using echo.

I would like to add a reference to my Web Root like this…

Proposed New Code



<?php echo '<img src="' . WEB_ROOT . 'images/some_image.jpg" width="150"
		 alt="Picture"
		 title="Picture" />
		<p>This is my article following here...</p>';


…but I seem to be having problems getting the syntax to work with my phpMyAdmin issue?!

Debbie

So that’s how you did it… don’t put PHP code into your database. There’s no phpMyAdmin issue. When you pull it back out and echo it, it’s just text, the code you put in there isn’t executed.

What you should do is set up your environment locally so that your site is at its own hostname, http://yoursite.local or something, rather than a subdirectory, and change your images/scripts/stylesheets to /images/some_image.jpg root-relative URLs, instead of these constants.

It’ll save you so much hassle. All 3 people that have participated in this thread have said so already.

Don’t want to stop using the config file of constants because you already put effort into it? You already hinted at that sentiment. It’s a sunk cost. It’s not relevant to what you should do going forward.

Time to sleep here, I’ll be back tomorrow.

I had some semi-enlightenment last night on the way back home. (Will revisit this part of this thread when I’m out of class.)

What you should do is set up your environment locally so that your site is at its own hostname, http://yoursite.local or something, rather than a subdirectory, and change your images/scripts/stylesheets to /images/some_image.jpg root-relative URLs, instead of these constants.

It’ll save you so much hassle. All 3 people that have participated in this thread have said so already.

Don’t want to stop using the config file of constants because you already put effort into it? You already hinted at that sentiment. It’s a sunk cost. It’s not relevant to what you should do going forward.

Time to sleep here, I’ll be back tomorrow.

Okay. Fair enough. I have been wrong in my approach.

I did ask Ralph above how he did what you and he are recommending in MAMP for OS X.

I’ll try to research this myself too, but since it seems that all of you “got the memo” - and I didn’t - then I’d prefer just have you tell me the correct way to do things. (Obviously when left to my own devices, I blow things up?!) :lol:

Thanks for the help so far everyone!

Debbie

Check out this page:

Creating a virtual host in MAMP

I was going to buy MAMP Pro but I’d have to upgrade to Snow Leopard and that is NOT going to happen!!

So, Ralph, can you please explain to me in layman’s terms what we are doing with these “virtual hosts”?

(I skimmed the link you sent and will do that after training today.)

By setting up a virtual host, what will I have to d/change as I go from Development (i.e. MAMP) to Production (i.e. GoDaddy)?

And how will this affect my code? (I guess it will make my life/code easier, right?!)

Thanks,

Debbie

Virtual hosts are how Apache maps hostnames (like “www.sitepoint.com” or “localhost”) to DocumentRoots (the folders with websites) you want it to host.

By creating a virtual host for each site you want to work on, you’ll be able to type something like http://yoursitename into your browser and see your site.

Since your sites will each have their own host and not sit in a subdirectory, all your paths to stylesheets, images and scripts that use URLs relative to the root will work exactly the same on your computer as they do on GoDaddy.

In other words, you won’t have to maintain a configuration file or make any changes when working on your site on your computer versus when it’s on your host. If you never hard code your hostname into your code (which you never need to), you can literally upload the code anywhere to any domain and your site will function without any change.

You do not need to buy anything. Apache, and everything else MAMP installs, is free software.

Still in training

Okay, that sounds pretty “cutting-edge” for me, but what about this last “kink”…

My life - in learning LAMP - has been relying heavily on MAMP and its built in link to phpMyAdmin and NetBeans.

Between those three apps I’ve got a great development environment that even a dummy like me can be pretty dangerous in?! :cool:

So if I follow the instructions that Ralph sent me a link on, and based on your description, what am I going to have to do with NetBeans?

Right now - when I get started every day - I launch MAMP, click on the phpMyAdmin link in MAMP and launch NetBeans. I then go into my “01_MyProject” folder in NetBeans, click on whatever php file I’m working on, enter/update code, and then do Shift + F6 to execute my .php page. (NetBeans does all of the rest as far as knowing how to do all of this “back-end plumbing” that has been messing me up so much!!)

What do I need to change in NetBeans so I can do what I just described above and keep my same development workflow? :frowning:

Thanks,

Debbie

Dan, the point is that the R=301 is a terrible way to eliminate the “missing support files problem” whereas either of the two recommended methods would resolve her problem. I’m not sure why you and Ralph are going off on tangents like this and hope that DD would actually try the solutions recommended.

Finally, altering the directory level by using PHP definitions the way you have is asking for problems - relative links never work correctly when you do that.

A better way to handle your development files (assuming that they’re duplicated in the development directory), is to create a single variable which will either be an empty string (production) or development/ for use within the development directory and <?=$development?> as part of your link. Of course, all this can be eliminated by using a local test server rather than abusing your production environment with testing. Because this is what you’re doing, why fiddle with nonsense like development directories?

Regards,

DK

DK…

That’s why bringing it up again, when and how you did, was counterproductive. You made her think that adding R=301, or some other change to the rule, might solve her problems. I’m sure you read between the lines and saw a bit of frustration at having to undo that.

Simply adding a slash before the URIs would not fix everything. The root of her site is not her document root. (“Sorry, DK, emphasis required”). Right now she accesses her site at http://localhost/01_MyProject/, so those URLs would not point to the correct path of her stylesheets or images.

She already has one. She just talked about it again in the post you replied to. That’s why we’re recommending she set up a virtual host, to make the root of her site the document root on both the development and production servers, AND add that slash.

Once we get to that point, the site will work the same everywhere, the config file won’t be necessary, etc etc, and the world will be at peace.

I can’t really comment on your workflow, but once you have your site working as you want in MAMP, you can just upload all your site files to the server, and export the database through PHPMyAdmin and upload that as well.

Glad someone was listening to me!! :wink:

She already has one. She just talked about it again in the post you replied to. That’s why we’re recommending she set up a virtual host, to make the root of her site the document root on both the development and production servers, AND add that slash.

Glad someone was listening to me!! :wink:

Thanks Dan!

Debbie

You’re not following me.

NetBeans has to be configured like any other IDE to point to the right physical and web paths so when I do Shift + F6 that it executes my php files.

If I take your and Dan’s advice on the virtual host, I can all but guarantee that I’ll need to change how NetBeans is currently configured.

I was hoping someone had some insight on that.


On a side note, if I follow the tutorial you posted, is there anything I should do to back up MAMP (or the related phpMyAdmin) before I attempt to set up a Virtual Host??

Hope to do this later today…

Thanks Ralph!

Debbie

I’m really struggling to get Virtual Hosts in MAMP working correctly.

httpd.conf


<VirtualHost *:80>
  DocumentRoot "/Users/user1/Documents/DEV/++htdocs/01_MyProject"
  ServerName dev
</VirtualHost>

<VirtualHost *:80>
  DocumentRoot "/Users/user1/Documents/DEV/++htdocs/00_AAA"
  ServerName testvh
</VirtualHost>

It seems like the first Virtual Host works if I type in [b]http://dev/[/b] however if I try out the second Virtual Host by typing in [b]http://testvh/[/b] it tries to go to www. testvh.com

In fact, about any name I try in VH#2 does the same thing?!

I don’t think I am understanding how this is supposed to work… :frowning:

Debbie

You need to enable named virtual hosts


NameVirtualHost *
<VirtualHost *:80>
  ServerName server1
  # etc
</VirtualHost>
<VirtualHost *:80>
  ServerName server2
  # etc
</VirtualHost>
# etc etc etc


Without NameVirtualHost only the first VirtualHost works (like you have now).
See core - Apache HTTP Server

Also, you probably this by now, but don’t forget to restart Apache every time you change httpd.conf

I don’t know how to do that. I was just suggewting you work locally and get everything the way you want it, then separately upload the whole lot t the server (which may mean a separate setup in NetBeans for the online site).

is there anything I should do to back up MAMP (or the related phpMyAdmin) before I attempt to set up a Virtual Host??

I don’t think so. The files just sit on your Mac as they are. You aren’t changing them at all.

The only think I’d do differently in your setup is change

ServerName dev

to

ServerName mysite.com

(obviously change mysite.com to the real site domain).

That way, all absolute URLs in the local files won’t need to change when you put them online. Otherwise you have the same problem as before.

You’re suggesting she change her hosts file to point the domain to her computer every time she works on the site? Maybe I don’t understand the suggestion.

And why ever hard code an absolute URL? I don’t do it once in any of my sites.

Or maybe I don’t understand my suggestion, which is more likely. I guess if she wants to work locally and online at the same time it won’t work.

And why ever hard code an absolute URL? I don’t do it once in any of my sites.

I don’t use absolute URLs either, but when working with a CMS, I find it records full URLs in its config file, and also creates a lot of absolute URLs with image links etc. ( :frowning: ), and to save me having to change all that when placing everything online, it’s simplest to have the site files in a local folder with the same name as the domain. I admit I’m still just learning about all this, so I’m not the best person to comment on it and thus will shuddup now. :smiley:

That wasn’t the problem, although that is where I was looking also?!

Turns out I was being a dummy and forgot to go back here and update the first part of the equation/tutorial after changing my virtual host names…

Then navigate to Macintosh HD: private: etc: hosts, and click Open…

Place your cursor on a new line at the end of the file, and type 127.0.0.1 followed by a space and the name of the virtual host you want to create. For example, to create a virtual host called mysite add this:

127.0.0.1 mysite

Argh!!

Debbie

It took me quite some time yesterday, but I think I’ve got it working… think

In NetBeans, I left Project Folder and Source Folder the same but changed my Project URL to http:// local.dev/ (in the case of this particular Virtual Host).

I created another test NetBeans Project, and things seem to be working, although I’m still trying to really get my hands around what all of this does and means.

[ot]Ya know, all of this started THREE WEEKS AGO when I was trying - and still am - add an “Add a Comment to an Article” module on my website to make it move Web 2.0 and since then I’ve had to: 1.) Convert physical articles to my MySQL database - which still isn’t working entirely, 2.) Create “pretty URLs” and learn about mod_rewrites, 3.) Struggle with Absolute Paths, and now 4.) Learn about Virtual Hosts?!

I am going CRAZY over all of this unforeseen extra work!!![/ot]

I don’t think so. The files just sit on your Mac as they are. You aren’t changing them at all.

I actually changed it so I could see hidden files and then made copies (i.e. backed up) my config files before following the link you sent.

Also, as usual, I commented the heck out of my files so I can roll-back anything that causes issues.

Debbie