Local webdeveloment with Apache: treating folders as domains

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
Jeroen Oosterlaar
Forum Commoner
Posts: 37
Joined: Sun Nov 06, 2005 4:12 pm

Local webdeveloment with Apache: treating folders as domains

Post by Jeroen Oosterlaar »

Hi everyone,

Currently I'm experimenting with URL rewriting (within Apache) for usabilty and search engine optimization purposes. Everything works fine on the hosting platform running the website on its domain. However, my local development setup is not quite suitable for testing URL rewriting locally, because the directory structure is different. Suppose I have a website for the domain site.com and I'm using URL rewriting.

Root:
http://www.site.com
(redirected to file: home.php)

Homepage:
http://www.site.com/home
(redirected to file: home.php)

Some product:
http://www.site.com/products/13
(redirected to file: products.php?productId=$1)

Now, locally I enter this site by the following URL:

http://localhost/site.com/

It follows that, especially with URL rewriting, this setup (where the root is different) is problematic regarding (absolute) paths.

My questions concerns this issue. Is there a way to configure Apache to treat directories on localhost as absolute domains? So, for example, that the root of http://localhost/site.com/ is not localhost, but, indeed, site.com? That way developing with URL rewriting is much easier, because the local setup, regarding the file structure, compares to the live one.

Thanks in advance!
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Just checkout the virtual host configuration stuff... eg:

Code: Select all

NameVirtualhost *:80

<VirtualHost *:80>
  ServerName gsf
  DocumentRoot "F:/websites/gsf/web"
  <Directory "F:/websites/gsf">
    AllowOverride All
    Options All
  </Directory>
</Virtualhost>

<VirtualHost *:80>
  ServerName timvw
  DocumentRoot "F:/websites/timvw"
  <Directory "F:/websites/timvw">
    AllowOverride All
    Options All
  </Directory>
</VirtualHost>
All i had to to is make sure that both gsf and timvw resolve to 127.0.0.1... And now i can surf to both sites :)
Jeroen Oosterlaar
Forum Commoner
Posts: 37
Joined: Sun Nov 06, 2005 4:12 pm

Post by Jeroen Oosterlaar »

timvw wrote:All i had to to is make sure that both gsf and timvw resolve to 127.0.0.1... And now i can surf to both sites :)
Thanks a lot :D!

I have succesfully configured the virtual host and I resolve the domain I use to 127.0.0.1. But now I have a problem with the .htaccess file, which is not being called for some reason. Does a certain directive need to be set to instruct Apache to call the .htaccess file in the root of the virtual host?


Never mind, I solved it :). It was due to an "AllowOverride None" directive that was set in the general scope.
Post Reply