DocumentRoot must be a directory CentOS6.5 - apache

I've been having a problem setting a directory in my virtualhosts, and am wondering if you guys can help. This is for Laravel and I have already made sure that the location exists and SELinux is disabled.
My config is as follows:
http://i.gyazo.com/31cdec5f9d830ec43923b4ccf1588d4c.png
I can't paste it here because the symbols mess up the formatting.

You should change your document root to:
/var/www/QuickPush/public
See the following virtualhost configuration I always use under CentOS 6:
<VirtualHost *:80>
ServerName quickpush.jackryder.co.uk
DocumentRoot /var/www/QuickPush/public
<Directory /var/www/QuickPush/public>
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
</Directory>
</VirtualHost>

Related

.htaccess file mod_rewrite redirecting to parent directory instead of sub-directory when file names are same in both directories

I am accessing the root directory via domain-A.com and a sub-directory via domain-B.com
All redirects are working properly for domain-B.com except those that are having same names for instance if root directory contains a file called abc.html and subdirectory also contains the file abc.html in that case accessing domain-B.com/abc.html shows the contents of domain-A.com/abc.html but the url remains the same i.e. domain-B.com/abc.html
I would like to know how can this be resolved.
I am using Ubuntu and these are the settings that I have made for various file
I have already enabled mod_rewrite using sudo a2enmod rewrite
.htaccess -
path /var/www/html
# Do not change this line.
RewriteEngine on
# Change domain.com to be your primary main domain. http://domain-b.com/
RewriteCond %{HTTP_HOST} ^(www.)?domain-b.com$
# Change 'subfolder' to be the folder you want to redirect request to.
RewriteCond %{REQUEST_URI} !^/domain-b/
# Don't change this line.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change 'subfolder' to be the folder you want to use for your primary domain.
RewriteRule ^(.*)$ /domain-b/$1 [L]
# Change domain.com to be your primary domain again.
# Change 'subfolder' to be the folder you will use for your primary domain
# followed by / then the main file for your site, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www.)?domain-b.com$
RewriteRule ^(/)?$ domain-b/index.html [L]
httpd.conf -
Path /etc/apache2/conf-available
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
000-default.conf -
Path /etc/apache2/sites-available
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
000-default.conf -
Path /etc/apache2/sites-enabled
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
Issue is with these 2 conditions:
# Don't change this line.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
Which means if a file or directory exists in site root dir then don't rewrite to sub-directory.
Just change your rule to this:
RewriteEngine on
# Change domain.com to be your primary domain again.
# Change 'subfolder' to be the folder you will use for your primary domain
# followed by / then the main file for your site, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www\.)?domain-b\.com$ [NC]
RewriteRule ^/?$ domain-b/index.html [L]
# Change domain.com to be your primary main domain. http://domain-b.com/
RewriteCond %{HTTP_HOST} ^(www\.)?domain-b\.com$ [NC]
# Change 'subfolder' to be the folder you want to redirect request to.
RewriteCond %{REQUEST_URI} !^/domain-b/ [NC]
# Change 'subfolder' to be the folder you want to use for your primary domain.
RewriteRule ^(.*)$ /domain-b/$1 [L]

vHost redirect not working at all

Goal: Redirecting every request to index.php except the files and folders (and their content) listed in the RewriteCond.
A friend did set up the server with me, but hadn't any time to fix this bug yet. The page automatically ends up at HTTPS.
When using this as 000-default.conf (/etc/apache2/sites-enabled/000-default.conf), the page just doesn't redirect to index.php. For example: Accessing www.page.com/uploads/38 works, although it should redirect to www.page.com/index.php. That's quite annoying as I'm emulating a filesystem and don't want to allow access to the files, at least not that way.
a2ensite 000-default.conf: Site 000-default.conf is already enabled
a2enmod rewrite: Module rewrite already enabled
This is my 000-default.conf:
<VirtualHost *:80>
ServerAdmin root#page.com
DocumentRoot /var/www/default
ServerName www.page.com
ServerAlias page.com
RewriteEngine On
<Location />
RewriteBase /
Options -Indexes
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_URI} !^(index\.php|css|fonts|gfx|js|favicon\.ico)
RewriteRule ^(.*)$ index.php [L,QSA]
</Location>
LogLevel warn
ErrorLog ${APACHE_LOG_DIR}/default_error.log
CustomLog ${APACHE_LOG_DIR}/default_access.log combined
</VirtualHost>
<VirtualHost *:443>
ServerAdmin root#page.com
DocumentRoot /var/www/default
ServerName www.page.com
ServerAlias page.com
RewriteEngine On
<Location />
RewriteBase /
Options -Indexes
Options +FollowSymlinks
RewriteCond %{REQUEST_URI} !^(index\.php|css|fonts|gfx|js|favicon\.ico)
RewriteRule ^(.*)$ index.php [L,QSA]
</Location>
LogLevel warn
ErrorLog ${APACHE_LOG_DIR}/default_error.log
CustomLog ${APACHE_LOG_DIR}/default_access.log combined
SSLEngine on
SSLCertificateFile /etc/ssl/page.com.crt
SSLCertificateKeyFile /etc/ssl/page.com.key
SSLCertificateChainFile /etc/ssl/comodo-ca.crt
</VirtualHost>
When looking at default_error.log, I often find stuff like this:
Request exceeded the limit of 10 internal redirects due to probable configuration error.
And also:
RSA server certificate CommonName (CN) `page.com' does NOT match server name!?
Thanks in advance.
The %{REQUEST_URI} variable starts with a /, your regex doesn't so that condition will always be true, including when the URI gets rewritten to /index.php, this is causing the loop.
Replace the block with:
RewriteBase /
Options -Indexes
Options +FollowSymlinks
RewriteEngine On
RewriteCond $1 !^(index\.php|css|fonts|gfx|js|favicon\.ico)
RewriteRule ^(.*)$ index.php [L,QSA]
Additionally, I'm guessing you've bought a certificate for the name "page.com", not "www.page.com", which means when you go to "www.page.com" and the browser sees a certificate for "page.com", it'll throw an exception. You need a cert for "www.page.com" (and optionally with "page.com" as an alternate name)/.
EDIT
Hmm, this didn't work for me either inside the <Location /> container. But this worked outside of the container by itself:
RewriteEngine On
RewriteCond $1 !^(index\.php|css|fonts|gfx|js|favicon\.ico)
RewriteRule ^/(.*)$ /index.php [L,R]

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

htaccess moved to vhost not playing nice

I wanted to move my .htaccess file - redirects into my vhost conf file...
This was working - but the htaccess redirects were not...
<VirtualHost *:80>
ServerName dev.x.com
ServerAlias dev.x.com
DocumentRoot "C:/wwwroot/x"
Alias /modules/ "C:/wwwroot/x/_my_modules/"
ErrorLog "C:/wwwroot/x/_my_logs/error.log"
CustomLog "C:/wwwroot/x/_my_logs/access.log" combined
<Directory "C:/wwwroot/x/_my_logs/" >
Options FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
Satisfy all
</Directory>
</VirtualHost>
Then i did this -
<VirtualHost *:80>
ServerName dev.x.com
ServerAlias dev.x.com
DocumentRoot "C:/wwwroot/x"
Alias /modules/ "C:/wwwroot/x/_my_modules/"
ErrorLog "C:/wwwroot/x/_my_logs/error.log"
CustomLog "C:/wwwroot/x/_my_logs/access.log" combined
<Directory "C:/wwwroot/x/_my_logs/" >
Options FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
Satisfy all
</Directory>
RewriteEngine on
# if requested URI is not a file and not a directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# externally redirect to /newLocation/{URI}
# RewriteRule (.*) index.php?_req=$1 [L]
# could use a redirect to a new directory ---
RewriteRule ^ /_mf_modules%{REQUEST_URI} [L,R=301]
</VirtualHost>
My objective was this:
I wanted any "directory" request - that didn't exist - to be rerouted to a directory of that name in the _my_modules dir.
IF a file did not exist I wanted to redirect to the to a directory of that name in the _my_modules dir.
So if www.x.com/xxx was the url... and 'xxx' dir didn't exist, I'd redirect to www.x.com/_my_modules/xxx
and like wise if www.x.com/xxx.php was requested - but xxx.php DIDN'T exist, they wou be redirected to www.x.com/_my_modules/xxx
however (even though there is an index.php in each dir) these always results in th eURL redirecting to this...
The requested URL /modules/modules/modules/modules/modules/modules/modules/modules/modules/modules/modules/modules/modules/modules/modules/modules/modules/modules/modules/_my_modules/ was not found on this server.
So I got fed up and changed the vhost file back to what I had to begin with, restarted Apache, and it's still redirecting, I can't get rid of the behavior.
You can move the RewriteRules from a .htaccess to the VirtualHost environment by putting them in a <Directory> environment in your vhost configuration.
In your case, try to cut and paste your rewrite rules in <Directory "C:/wwwroot/x/_my_logs/" >
If you really want to put them in the VirtualHost environment, you have to modify the paths in them: RewriteRules in .htaccess or are relative to the directory, RewriteRules in the VirtualHost are absolute to the root of the filesystem or the DocumentRoot.
rewritecond example:
RewriteCond %{REQUEST_FILENAME} !-f
should be in vhost:
RewriteCond /your/documentroot/%{REQUEST_FILENAME} !-f
rewriterule example:
RewriteRule (.*) /your/documentroot/index.php?_req=$1 [L]
should be in vhost:
RewriteRule (.*) index.php?_req=$1 [L]

Per-server rewriterules not working

I've got a VirtualHost directive in /etc/apache2/openpanel.d/www.example.com.conf:
<VirtualHost *:80>
ServerAdmin "jon#example.com"
DocumentRoot /home/openpanel-admin/sites/www.example.com/public_html
ServerName www.example.com
ServerAlias example.com
<Directory /home/openpanel-admin/sites/www.example.com/public_html>
AllowOverride All
Allow from all
</Directory>
Include /etc/apache2/openpanel.d//www.example.com.inc/[^.#]*
Include /etc/apache2/openpanel.d//global.inc
</VirtualHost>
And I've the following in /etc/apache2/openpanel.d/www.example.com.inc/RewriteRules
<Directory /home/openpanel-admin/sites/www.stallfinder.com/public_html>
Options +FollowSymlinks
RewriteEngine On
RewriteRule agricultural-show-c780.html /search/event/agricultural-shows/1/ [R=301,L]
RewriteRule antique-fair-c596.html /search/event/antique-and-collectors-fairs/1/ [R=301,L]
RewriteRule baby-and-toddler-fairs-c896.html /search/event/baby-and-toddler-fairs/1/ [R=301,L]
RewriteRule book-fair-c631.html /search/event/book-fairs/1/ [R=301,L]
# etc... there are ~3000 of these
</Directory>
And I've got an .htaccess file in /home/openpanel-admin/sites/www.example.com/public_html:
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
# Search pages
RewriteRule ^search/(stallholder|event)/?$ /find-$1.php [L]
RewriteRule ^search/(stallholder|event)/([^/]+)/([0-9]+)/? /$1.php?name=$2&id=$3 [L]
But the RewriteRules in the include file (RewriteRules) don't appear to be parsed/used.
The file is being included because I can put non-allowed stuff in there and apache will fail to load the config file, but if I turn on Apache redirect logging, then I only see [perdir] lines as if all the RewriteRules I've got in the RewriteRules include aren't being processed.
The global.inc file is empty, and the RewriteRules in my .htaccess file work fine.
Any clue what I'm doing wrong?
Try adding RewriteOptions directive into your .htaccess to allow executing rewrite rules on parent (upper) level.
http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriteoptions