Change root on localhost

I’m playing around with a site on my WAMP server,
I have a link set up like this

<a href="/">...</a>

at the site at http://localhost/ronisvanhelms-new/ which seems to go to http://localhost, and since I want it to go to http://localhost/ronisvanhelms-new/
I thought id add this to the .htaccess file in ronisvanhelms-new

RewriteEngine on
RewriteCond %{HTTP_HOST} ^localhost$ [NC,OR]
RewriteCond %{HTTP_HOST} ^localhost$ 
RewriteCond %{REQUEST_URI} !ronisvanhelms-new/
RewriteRule (.*) /ronisvanhelms-new/$1 [L]

Was that not right?

luke,

Yes … that is NOT right!

My recommendation is to learn how to create Virtual Hosts within your test server. There are three steps:

  1. Edit httpd-vhosts.conf (it’s in Apache’s config/extra directory) and create a new virtual host entry like:

<VirtualHost 127.0.0.1:80> ServerName RVH DocumentRoot C:/RVH ServerPath C:/RVH </VirtualHost>

Where RVH is your virtual host name (I use a lot of initials for mine) and the website files are located at C;\RVH. Obviously, change the name and location to suit your own preferences.

  1. Edit your hosts file (it’s extensionless and located at C:\Windows\System32\drivers\etc\hosts) AS ADMINISTRATOR and add the one-liner:
127.0.0.1 RVH

If you had not RUN AS ADMINISTRATOR, you will NOT be able to save this file!

  1. Restart Apache.

You will then be able to access your new virtual host using http://RVH.

Okay, you wanted to change your virtual host to a subdirectory within your canned app (WAMP) but why not do it right? Using virtual hosts will make your life so much easier.

Regards,

DK

I tried following the steps and something is amiss, I made those changes to both files (Opened the notepad program as ADMIN) (screenshot)

the hosts file

#...
127.0.0.1       localhost
127.0.0.1       ronisvanhelms

the httpd-vhosts.conf file

#...
<VirtualHost 127.0.0.1:80>
ServerName ronisvanhelms
DocumentRoot C:/wamp/www/ronisvanhelms-new
ServerPath C:/wamp/www/ronisvanhelms-new
</VirtualHost>

saved em both, restarted Apache,

I go to localhost


Click on the ronisvanhelms-new project which brings up the site,

Heres the source code of the Home link

<a href="/">Home</a>

Im trying to get that link to go to itself as im trying to make the root localhost/ronisvanhelms-new but instead its going to localhost.

luke,

Open hosts again and you will see that you have NOT made the necessary change BECAUSE Notepad will NOT let you save a file without the txt extension. I use EditPad Lite but you should be able to use notepad++ or any other GOOD text editor (Notepad does not qualify in this category).

Regards,

DK

IMHO, Notepad is good for use as a, errm, note pad, but not as a code editor.
Similarly, Word might be great at creating print documents, but please, don’t use it for working with code (or risk learning the hard way)

I currently use Notepad++ on my Windows7 and like it for “outside of an IDE” work.

ok, opened that file in notepad++

luke,

GREAT! Assuming that you ran Notepad++ AS ADMINISTRATOR, simply save the hosts file and restart Apache then access your virtual host via http://ronisvanhelms/.

Edit: I have ASS-u-me’d that WAMP did not install in a Program Files directory or you would have to have run Notepad++ AS ADMINISTRATOR in order to save the httpd-vhosts.conf file, too.

Regards,

DK

ok, did that and heres what happens at
http://ronisvanhelms/

But thats not really what im trying to do (Im bad at explaining it)

From the website im trying to fix at

http://cdn.discourse.org/sitepoint/uploads/default/_optimized/a6f/b48/7fea1f7725_690x388.png
(http://ronisvanhelms/ronisvanhelms-new/ and http://localhost/ronisvanhelms-new/)
I have a link set up like

<a href="/">Home</a>

(I also have images also)

<img src="/images/profile.jpg"">

However, the page doesn’t see them, ,the link goes to localhost instead of localhost/ronisvanhelms-new/

so im trying to make / go to localhost/ronisvanhelms-new

Off-topic

LOL
You know the saying about that word don’t you?
And remember, this is Windows.
As best as I can figure, the “as Admin” is needed for files that don’t follow the filename.extension format.

luke,

Have you named a DirectoryIndex in your .htaccess file? If not, you can’t use / as the last character in the URI so you’d better add the file name (and extension) that you want to view.

Regards,

DK

is this a good way?

should I put this in my .htaccess file

RewriteEngine on
RewriteCond %{HTTP_HOST} ^localhost$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.localhost$
RewriteCond %{REQUEST_URI} !ronisvanhelms-new/
RewriteRule (.*) /ronisvanhelms-new/$1 [L]

I’m not sure if I should change the DirectoryIndex as I want to change what the root is, so that / points to localhost/ronisvanhelms-new/

luke,

Without looking at that link, the obvious answer is “not only no but @#$% no!”

DirectoryIndex index.php index.html index.htm default.whatever

That is the “official” way to change the DirectoryIndex (default script) which will look through the list and serve the first file found.

Note: This should already be in your httpd.conf file but, if not, add it there, add it in your httpd-vhosts.conf or add it in your ronisvanhelms .htaccess file.

WHY would you insist on looking through the localhost directory for a virtual host which can be stored elsewhere (and has NOTHING to do with localhost as a URL)? For that matter, WHY would you use the -new at the end of your virtual host when you did not create it with -new?

IF you were able to save the hosts and httpd-vhosts.conf files and IF you restarted Apache after that, access your new virtual host using http://ronisvanhelms/ and let the DirectoryIndex serve the appropriate file from the C:/wamp/www/ronisvanhelms-new directory. THAT is what virtual hosts can do for you if you let them!

Regards,

DK

ok, im really tying to understyand this…
heres the file

Here’s the other file

I restarted apache, go to http://ronisvanhelms-new/


(the WAMPSERVER Homepage)
but im trying to make http://ronisvanhelms-new/ go to http://ronisvanhelms-new/ronisvanhelms-new/

instead (sorry if I confused you or am not explaining it well)

luke,

Okay, I can see:

  1. hosts is correctly configured for ronisvanhelms-new as a locally hosted virtual domain.

  2. httpd-vhosts.conf is properly configured to add ronisvanhelms-new as a virtual domain.

  3. The WAMP server is improperly configured (I don’t know how/why because I will not use “canned apps” for a snapshot view of a server. There is NOTHING which should allow that configuration page to be displayed.

  4. ronisvanhelms-new/ronisvanhelms-new should not exist (or the virtual domain should be to that directory rather than the first level - WHY did you do that?).

  5. You’ve created a WordPress website in the second level directory.

I do NOT see the .htaccess file in the DocumentRoot (currently the first level) which specifies that the index.php (or any other in the DirectoryIndex list) file should be served. In the second level, WordPress would have specified a redirection to index.php so that does not need a DirectoryIndex directive (albeit, it should already be in the httpd.conf).

Please correct the confusion caused by the double directories.then show your .htaccess file(s). With this strange setup, we need to see more to make sense of what you’ve done. Okay, okay, maybe it’s just me that’s dense and I need that “handholding.”

Regards,

DK

oj, I understand that I set up the hosts file and the httpd-vhosts.conf file correctly (that was verifiable cause http://ronisvanhelms-new/ works)
You say the WAMP server is not configured properly?
Should I ask http://forum.wampserver.com/ how to configure it for my needs?
ronisvanhelms-new/ronisvanhelms-new did look strange to me, but I thought that was because I set

127.0.0.1       localhost
127.0.0.1       ronisvanhelms-new

(is it ok thats it point to the same # as localhosts?)

How do I set the virtual directory to the ronisvanhelms-new directory rather than the 1st level?
(the 1st level is the WAMPSERVER Homepage right?)

Heres my .htaccess file (on the right, you can see how the site is set up (as far as the directory structure)


Thanks again and sorry if im not to quick on the uptake.

Hi luke,

Correct. You should never see any configuration file via Apache. Perhaps that’s a “feature” of WAMP, though.

It is not only okay but MANDATORY that you use 127.0.0.1 for your virtual hosts located at localhost (your computer). hosts will sort out the different virtual hosts for you.

You have already set the virtual host DocumentRoot to ronisvanhelms-new. Therefore, merely connect to it via http://ronisvanhelms-new. The simple fact that you then see http://ronisvanhelms-new/ronisvanhelms-new indicates a problem - likely that EITHER your virtual host is pointed to localhost as the DocumentRoot (it’s not from what I’ve seen of your files) OR WordPress is not setup to use the ronisvanhelms-new directory as the DocumentRoot. Translated: Check your WordPress configuration.

Okay, from the microscopic text of your image, your mod_rewrite (WordPress configuration) is all wrong. WordPress should be installed in the ronisvanhelms-new directory (making the RewriteBase redundant - DELETE) and the RewriteRule should ot be redirecting to the ronisvanhelms-new subdirectory (of ronisvanhelms-new, the domain). It might help you if DW is conrrectly configured (test server) to point to the ronisvanhelms-new directory, too.

Please Google Virtual Host for a better picture of what I’ve been saying for the last dozen posts. It is a domain located on your server and it’s just that simple! BTW,

I’ve NEVER seen any webmaster use a wordpress directory for a website which is run by WP! Perhaps a visit to WP’s forum may help you resolve that issue (I’d move all the files from the wordpress subdirectory to the DocumentRoot but that’s your choice).

WARNING: If you’re going to run a (production, i.e., live to the world) WP website, you MUST plan on checking for updates AT LEAST DAILY because WP is hacked regularly. If you don’t, plan on rebuilding your website regularly after being hacked by the script kiddies that download exploits from hacker websites. IMHO, it’s not worth running a WP website because of all the additional work trying to catch up with the hacker community (and you’ll NEVER get ahead of them).

Regards,

DK

ok, thanks…;.

Hi Luke,

You may be interested in the setup I developed because I found the “Localhost Virual Host” convoluted and limited.

Localhost stores a mirror image of the Remote Server files. The only differences are the index.php and .htaccess files.

Calling “http://localhost/_menu/index.php

dynamically displays all directories on the Localhost with links to:

http://localhost/PROJECT_SWITCHER.php?path=selected_path

The PROJECT_SWITCHER.php uses $_GET[‘path’] and copies the two following files

./selected_path/index-LOCALHOST.php to “http://localhost/index.php
./selected_path/.htaccess-LOCALHOST to “http://localhost/.htaccess

http://localhost/index.php” is called after the two files have been copied

You then have a working copy of your remote site.

This system does take time setting up but once configured projects can be toggled or switched off by calling the _menu system again.

http://localhost/PhpMyAdmin” also requires setting but is well worth the extra effort.

Adding a new project or Version_002 requires creating a new directory with another index-LOCALHOST.php and .htaccess-LOCALHOST files. The _menu system automatically includes the new path.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.