Reputation: 9556
I can not manage to setup a virtual host on url with a subdir ... I need to run my project on address like this:
http://www.projects.loc/project1/
This should mimic installation on a web server where the address will be like
http://www.someServer.com/projects/project1/
I need to adjust the redirects to '/' so it goes back to www.projects.loc/project1/
in the hosts.txt I have:
127.0.0.1 www.projects.loc
vhosts are enabled and the httpd-vhosts.conf looks like this:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "D:/Projects/Project1/public/"
ServerName www.projects.loc/project1/
</VirtualHost>
What am I missing ?
EDIT: .htaccess looks like this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php [NC,L]
the application is running normally on clean domain, but I can not manage to config it to run on domain.com/some_dir/
Edit:
solved this!
NameVirtualHost *:80
<Directory "D:/Projects">
allow from all
</Directory>
<VirtualHost *:80>
DocumentRoot "D:/Projects"
ServerName www.projects.loc/
Alies /project1 /Project1/public/
</VirtualHost>
Note: this is the minimal configuration good only for development environment,
check the accepted ansler from @M-z for full details for production evironment.
Upvotes: 1
Views: 5389
Reputation: 1845
probably you already solved that question. Anyway, I was looking today a similar thing, therefore I document the solution here:
You don't want to write slashes in the ServerName
ServerName www.projects.loc/project1/
If you just have the one project, called "project1", you can easily get the job done with "ServerPath", your vhost configuration will then look like this:
<VirtualHost *:80>
ServerName projects.loc
ServerAlias www.projects.loc
ServerPath /project1/
DocumentRoot /PATH/public_html
ErrorLog /PATH/error_log
CustomLog /PATH/access_log combined
DirectoryIndex index.html index.htm index.php index.php4 index.php5
<Directory /PATH/public_html>
Options -Indexes +IncludesNOEXEC +FollowSymLinks
allow from all
</Directory>
</VirtualHost>
Through the ServerPath you are able to mount the directory to projects.loc/project1
Anyway, assuming you have several projects (project1, project2) which you want to bind to projects.loc/project1, projects.loc/project2, etc. use "Alias". Your vhost configuration file should then look like this:
<VirtualHost *:80>
ServerName projects.loc
ServerAlias www.projects.loc
DocumentRoot /PATH/public_html
ErrorLog /PATH/error_log
CustomLog /PATH/access_log combined
DirectoryIndex index.html index.htm index.php index.php4 index.php5
<Directory /PATH/public_html>
Options -Indexes +IncludesNOEXEC +FollowSymLinks
allow from all
</Directory>
Alias /project1 "/PATH/public_html/project1"
<Directory "/PATH/public_html/project1">
DirectoryIndex index.html index.htm index.php index.php4 index.php5
Options -Indexes +IncludesNOEXEC +FollowSymLinks
allow from all
</Directory>
Alias /project2 "/PATH/public_html/project2"
<Directory "/PATH/public_html/project2">
DirectoryIndex index.html index.htm index.php index.php4 index.php5
Options -Indexes +IncludesNOEXEC +FollowSymLinks
allow from all
</Directory>
</VirtualHost>
Your application laying in the folder /PATH/public_html/project1 will then be available at projects.loc/project1, your application laying the folder /PATH/public_html/project2 will be available at projects.loc/project2 and so on.
I'd rather use different subdomains for the different applications. This has the benefit of having own configuration files for every subdomain host, which makes also error and access log handling easier. By using the Alias, configuring different error and access logs will be more difficult, if you want to have them per application.
Further reading:
Concerning Alias: http://httpd.apache.org/docs/current/mod/mod_alias.html
Concerning ServerPath: http://httpd.apache.org/docs/2.2/vhosts/examples.html#serverpath
Upvotes: 3