2

My web host points my "main" domain name to the root www folder. The web files for that site are located in the "www/app/webroot" folder. I currently have the site up and running using the following in the htaccess file:

RewriteBase /
RewriteEngine on
RewriteRule    ^$ app/webroot/    [L]
RewriteRule    (.*) app/webroot/$1 [L] 

I'm trying to start a dev site for the same site. I made a folder named "dev" in the www folder. So, the web files for this folder are in: "www/dev/app/webroot" I have a sub-domain pointing to the dev folder. When I use the same htaccess as above in the dev folder, it doesn't work because (I believe) it is inheriting the settings from the root www folder. When the page loads, it just comes up blank. How do I set up my htaccess files to allow for both sites?

Thanks in advance for any help! I'm obviously a novice at this stuff.

Randy
  • 597
  • 1
  • 9
  • 20

3 Answers3

8

So we'll try to clean the things :-)

Avoid using .htaccess. All the settings in a .htaccess in a directory /foo/bar can be set in apache configuration as a Directory setting (.haccess is usefull if you provide limited access on apache conf, if you own the server don't use it).

<Directory /foo/bar>(...)</Directory>

Then you can access your sites with named based virtualhosts. Verify you have this option:

NameVirtualHost *:80

When you have it nice things can start. This will be your virtualhost for your 1st app:

<VirtualHost *:80>
    ServerName app
    ServerAlias www.app.somwhere.com
    ServerAlias app.somwhere.com
    DocumentRoot /www/app/webroot
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /www/app/webroot>
        Options Indexes FollowSymLinks
        # this prevent.htaccess reading, remove if you want .htaccess
            AllowOverride None
            # allow web access 
        Order allow,deny
        allow from all
    </Directory>
</VirtualHost>

Most apache settings can be define here. Only for your 1st app. Apache will serve this configuration for all requests done for the site name 'app', or 'www.app.somwhere.com', or 'app.somwhere.com'. You can define a lot of alias(ServerAlias)., and only one name (ServerName).

Then if you go in your browser and type http://app/ your browser won't find the server, so set it in your /etc/hosts. This is what every people wanting to access your app should have in the hosts file until you get a real DNS (assuming your 1st app is app.somwhere.com and the second foo.somwhere.com and 92.128.52.226is your external IP):

127.0.0.1 app.somwhere.com app foo foo.somewhere.com
92.128.52.226 app.somwhere.com app foo foo.somewhere.com

And now let's add another virtualhost for your second app:

<VirtualHost *:80>
    ServerName foo
    ServerAlias www.foo.somwhere.com
    ServerAlias foo.somwhere.com
    DocumentRoot /www/foo/webroot
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /www/foo/webroot>
        Options Indexes FollowSymLinks
        # this prevent.htaccess reading, remove if you want .htaccess
            AllowOverride None
            # allow web access 
        Order allow,deny
        allow from all
    </Directory>
</VirtualHost>

And etc. Don't forget to restart your apache. No rewrite rule. nice virtualhosts is the 1st step of a nice configuration, you will be able to define rules, directory or location specific things per name used. Even php configuration can be set per virtualhost with php_value instead of a global shared one on php.ini.

type

apache2 -S

to get the list of your virtualhosts, you'll see that the first one is the 'default' one, if apache does'nt understand the name of the requested site it will serve this default one (so you could ad a specific virtualhost on top to handle theses cases).

regilero
  • 29,806
  • 6
  • 60
  • 99
0

Try adding dev/ to the paths in lines 3 and 4 to your dev .htaccess.

WNRosenberg
  • 1,862
  • 5
  • 22
  • 31
  • I tried that, it didnt work. If I add it in the root folder, it messes up the main site. If I add it in the dev folder, I get an error, I think because its looking for www/dev/dev/app/webroot, which doesnt exist. – Randy Jan 04 '11 at 14:52
0

Maybe you should remove the "RewriteBase /" line in the .htaccess in your dev folder?

uzar
  • 31
  • 3