Get 403 error when create multiple vhost outside the XAMMP htdocs - apache

I know this is quite old problem, but i have no luck when trying to find the right solution. I have tried every possible configuration but still no luck. I'm working on PHP project using laravel. I got no problem at all when set up the laravel.labs as vhost INSIDE the htdocs. But when I move it into separated folder which is C:\vhosts i got this 403 error. The purpose of vhosts folder is to hold multiple vhost. The following are my configuration:
System:
windows 7 64-bit
XAMPP v 1.7.7
Apache/2.2.21
PHP: 5.3.8
httpd.conf :
# Virtual hosts
Include "conf/extra/httpd-vhosts.conf"
httpd-vhosts.conf
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot C:/xampp/htdocs
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot c:/vhosts/laravel_labs/public
ServerName laravel.labs
</VirtualHost>
c:\windows\system32\driver\etc\host
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
127.0.0.1 laravel.labs
.htaccess (inside the C:\vhosts\laravel_labs\public)
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Can anyone help to find something that i missed? any advice guys? thanks

Every time you add a new Alias or DocumentRoot, you need a <directory> section just like the one for your default DocumentRoot. Depending on your release, this either has something like
Order deny,allow
or
require all granted

Finally i found The answer for this problem. I have to add some lines in httpd.conf
Something like this:
Alias /laravel_labs/public "C:/vhosts/laravel_labs/public/"
<Directory "C:/vhosts/laravel_labs/public/">
AllowOverride All
Order Allow,deny
Allow from all
</Directory>
See the detail explanation here :
http://www.youtube.com/watch?v=Z250saioXIs

Related

How to make domain accessible with www on apache 2.4

I want my laravel app accessible with or without www on the url. like [http://laracasts.com][1]. when I hit http://example.com it works. But when I hit http://www.example.com, or http://www.example.com/contact I'm getting 404 error. How can I solve this? I'm using apache 2.4.7 on Ubuntu and here's my example.com.conf
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
ServerAdmin foo#bar.com
DocumentRoot /var/www/myproject/public
<Directory /var/www/myproject/public/>
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/example-error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
and here's my /etc/hosts file
127.0.1.1 example
127.0.0.1 localhost
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
xxxx::0 ip6-localnet
xxxx::0 ip6-mcastprefix
xxxx::1 ip6-allnodes
xxxx::2 ip6-allrouters
xxxx::3 ip6-allhosts
and .htaccess:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
about server stuff, i'm noobs.
Your apache configuration is correct. However, you need to enable the rewrite module:
sudo a2enmod rewrite
sudo service apache2 restart
If you use a registered domain, this is enough. If you just use a "local" domain for development, you have to add this dumping domain into your hosts file at /etc/hosts. For example, when working with local environment, I usually use a domain .local, I'll add this line to make the domain example.local work:
127.0.0.1 example.local
You will need to include all the possible domain/subdomain name combinations that you would like to use in your hosts file.
127.0.0.1 www.example.com
127.0.0.1 example.com
In regards to http://www.example.com/contact does http://example.com/contact work?

Codeigniter controller in subdirectory not working in virtual host

I need help with CodeIgniter -- trying to it to work in virtual host envirnoment in Ampps.
I have been following the following tutorial:
http://net.tutsplus.com/tutorials/php/basecamp-style-subdomains-with-codeigniter/
I am trying to have two installations of CodeIgniter running in two directories:
/students and
/teachers
www.test.com -> goes to /teachers directory
www.user1.test.com -> goes to /students directory
I have the above working on my local machine. The different URL's take me to the correct directory. CI works. Problem arises when I try to access controller using redirect.
if I try to redirect('error') I get:
user2.test.com/user2.test.com/error
Also get an "internal server error"
if I type in
user2.test.com/error
I get an "internal server error"
if I type in
user2.test.com/index.php/error
I get desired result
It works if I try to load view directly in
$this->load->view('error')
I think I need help with the urls and paths. Any guidance most gratefully received.
Nothing particularly enlightening in CI log files
In Apache logs I find:
Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
Things I have changed:
htaccess in root - changed rewrite base. Also takes out index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /students/
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
application/config.php
$config['base_url'] = $_SERVER['HTTP_HOST'];
As per tutorial. Needs to be dynamic.
my Apache hppd-vhosts.conf file
NameVirtualHost 127.0.0.1:80
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "C:/Program Files/Ampps/www/teachers"
ServerName test.com
ServerAlias test.com
<Directory "C:/Program Files/Ampps/www/teachers">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/Program Files/Ampps/www/students"
ServerName test.com
ServerAlias *.test.com
<Directory "C:/Program Files/Ampps/www/students">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
index.php in root
kept as is. Things got worse when I tried to change these
$system_path = 'system';
$application_folder = 'application';
what about your host file? your host file should be 127.0.0.1 test.com and first try to disable the student sub domain and see if it dose work. Its look like your both ServerName test.com is same try to change the other one with student.com and see whats happen most probably both are conflicting

apache vhosts ignores rewriterule

I have the following vhosts file:
directoryindex .index.php index.html index.php
options -indexes -multiviews +followsymlinks
<directory /Volumes/dev1/http>
allowoverride all
</directory>
<virtualhost *:80>
documentroot "/Volumes/dev1/http"
rewriteengine on
rewriterule ^.*$ /msg.php [l]
</virtualhost>
There are other virtual hosts, but the one from above is the "catch-all". The problem is that the rewriterule is totally ignored.
Going to site.com gives a 403 error and site.com/test just returns a 404 Not Found page instead of serving the msg.php file.
The server is a OS X 10.8 Server running Apache 2.2.24
it seems that you are in the wrong dir.
For what reason ever Apple left the .conf files for the virtual host under this directory.
/Library/Server/Web/Config/apache2/sites

File not found with VirtualHost and mod_rewrite

I'm bulding a RESTful api based on Tonic.
On my developer machine and our stage server we use virtual hosts.
Tonic uses a .htaccess file to translate the incomming calls to it's dispatcher.php file. This works fine on servers without VirtualHosts enabled.
However if i enable VirtualHosts i get a file not found even thought the path and name to the file is correct.
Here is the VirtualHost setup on my developer machine.
<VirtualHost *:80>
ServerAdmin admin#xxxxxxxxxxxx
ServerAlias *.dev.xxxxx
VirtualDocumentRoot /home/xxxxxxxx/workspace/%1
<Directory /home/xxxxxxxx/workspace/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
And Tonic's .htacces located in a folder called rest in the project root:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !dispatch\.php$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* dispatch.php [L,QSA]
</IfModule>
A call to http://project.dev.xxxxx/rest/ gives:
Not Found
The requested URL /home/xxxxxxxx/workspace/project/rest/dispatch.php was
not found on this server.
Apache/2.2.22 (Ubuntu) Server at xxxxxxx Port 80
It appears as though you're misusing VirtualDocumentRoot. Try changing it to:
DocumentRoot /home/xxxxxxxx/workspace/project/rest
Also, here's a good explanation on the VirtualDynamicRoot: Dynamically configured mass virtual hosting
Hope that helps.

Apache - Can no longer use mod_rewrite after adding virtual directory

My apache server is set up with a very basic configuration. I used to serve just one website from apache, let's call it example.com. Within the httpd.conf file, I had some code to force the website to always show www in the url.
I recently added a subdomain for the site, blog.example.com. In order to do this I needed to create 2 virtual directory directives within my httpd.conf file.
NameVirtualHost *:80
<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/html
</VirtualHost>
<VirtualHost *:80>
ServerName blog.example.com
DocumentRoot /var/www/blog
</VirtualHost>
Immediately after this, I kept my rewrite code:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) http://www.example.com/$1 [L,R]
The problem is that this after adding the Virtual Directory code, the rewrite code is no longer working. I tried creating the following Directory directive, which doesn't seem to work at all.
<Directory "/var/www/html">
Options Indexes MultiViews FollowSymLinks
Order Deny,Allow
Allow from all
AllowOverride All
</Directory>
Additionally, I tried creating a .htaccess file in the html folder of the website and restarting apache, but nothing that I put in there is getting noticed at all.
Any help is greatly appreciated. Thanks!
Answer from comment by original poster:
Ok, I figured it out. I just needed to move the rewrite logic within the start and end Directives. Thanks for the help #animuson. – Henry Wrinkler