Vhosts not redirecting - apache

I have a server running Ubuntu 14.04 LTS and I am trying to set up vhosts. What I did already is,
1) Created 2 files desktopia.be.conf and everybodycreative.be.conf which look like this
desktopia.be.conf:
<VirtualHost *:80>
ServerAdmin your_email_address
ServerName desktopia.be
ServerAlias www.desktopia.be
DocumentRoot /var/www/desktopia
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/desktopia>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
</VirtualHost>
everybodycreative.be.conf:
<VirtualHost *:80>
ServerAdmin your_email_address
ServerName everybodycreative.be
ServerAlias www.everybodycreative.be
DocumentRoot /var/www/everybodycreative
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/everybodycreative>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
Under the www folder, I made 2 folders named desktopia and everybodycreative.
After I did that, I ran the following commands
sudo a2ensite desktopia.be
sudo a2ensite everybodycreative.be
and restarted the apache2 service.
Now the problem is that when I connect on one of the 2 domain names, I just get to see the content of my www folder as you can see here http://desktopia.be/
If anyone can tell me where I should look or what more information is needed to fix this problem, please ask me so that I can fix this. This has been bothering me for a few days already and I need this fixed asap.
Thanks for helping me already :)

I think you'll need to run
a2enmod rewrite
to turn on rewrite module.
Then in the relative folder .htaccess
RewriteCond %{HTTP_HOST} ^(.+)\.desktopia\.be
RewriteCond %{HTTP_HOST} !^www\.desktopia\.be [NC]
RewriteRule ^(.+)$ /var/www/desktopia/%1/$1
same for other url,
I haven't tried it so you may need to modify something in the .htaccess folder code

You need to enable the NameVirtualHosts directive in your config.

Related

Htaccess issue with RewriteOptions InheritBefore

I have got two htaccess:
api/public/.htaccess
RewriteRule . index.php
api/public/cron/web/.htaccess
RewriteEngine On
RewriteOptions InheritBefore
I set my vhost for cron:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName cron.api.local
ServerAlias www.cron.api.local
DocumentRoot /var/www/api/public/cron/web
ErrorLog ${APACHE_LOG_DIR}/api_cron_error.log
CustomLog ${APACHE_LOG_DIR}/api_cron_access.log combined
<Directory "/var/www/api/public/cron/web">
Options Indexes FollowSymLinks MultiViews
Require all granted
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
Url http://cron.api.local/up returns 404 status but when i replace RewriteOptions InheritBefore with RewriteRule . index.php then it works. What is wrong?
I use apache 2.4.18 and ubuntu 16.04.
To fix this issue follow this:
sudo nano /etc/apache2/apache2.conf
Find:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted </Directory>
Replace With:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Exit and save and restart apache with command
sudo systemctl restart apache2
Reverence:
Apache mod_rewrite is enable on server but not working?

.htaccess deny from all doesn't work

my problem is that I want to deny the access to a folder but I can't.
I've put a .htaccess file in this folder with just these lines:
order deny,allow
deny from all
Any idea of what can be happening?
I get it! It was due to the apache configuration. In my foo.conf of sites-avaiables directory I had:
AllowOverride None
As apache doc says, AllowOverride Description: Types of directives that are allowed in .htaccess files
When it is changed to:
AllowOverride All
it works perfectly!
You can also configure it with specific options:
AllowOverride directive-type
directive-options at: apache.org
I had the same issue using that method. Try this instead:
RewriteEngine On
RewriteCond %{REQUEST_URI} foldername
RewriteCond %{REMOTE_ADDR} !^111\.222\.333\.44$
RewriteRule . - [R=404,L]
With this method you need to add your own ip.
Options: instead of the last line being a 404 page not found:
RewriteRule . - [R=404,L]
you can change it to a 403 forbidden:
RewriteRule .*? - [F]
or redirect to your homepage:
RewriteRule . http://www.domain.com/ [R,L]
you need to do two things,first, change the conf of apache to allow override,
second, to change the conf of a hosting to allow override
first
nano /etc/apache2/apache2.conf
<Directory /var/www/html/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
and change it to;
<Directory /var/www/html>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Second
cd /etc/apache2/sites-available
nano yourdomain.com.conf
add the following codes into it,
<Directory "/var/www/html/yourdomain.com/public_html">
AllowOverride All
Require all granted
</Directory>
after adding
<VirtualHost *:80>
ServerAdmin support#yourdomain.com
ServerName yourdomain.com
ServerAlias www.yourdomain.com
DocumentRoot /var/www/html/yourdomain.com/public_html/
<Directory "/var/www/html/yourdomain.com/public_html">
AllowOverride All
Require all granted
</Directory>
Use this:
<Directory /folder_name>
Order Deny,Allow
Deny from all
</Directory>
Its better to add a rule to allow your ip address. You can use allow from your_ip_address for this. Be careful with the ip address as it can be shared. You can check your ip address using http://www.whatismyip.com/

.htaccess rewrites not being read

I have the following in htaccess:
RewriteEngine on
RewriteRule ^list/([A-Za-z0-9_\.-]+).html?$ list.php?table=$1 [QSA,L]
In virtualhosts:
ServerName localhost
DocumentRoot "c:/wamp/www"
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
<VirtualHost *:80>
DocumentRoot "c:/wamp/www/kurz/site/www"
ServerName kurz.local
<Directory c:/wamp/www/kurz/site/www>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
in apache config:
DocumentRoot "c:/wamp/www/"
<Directory />
Options FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
</Directory>
Now the weird problem is:
there is a rewrite happening, even AFTER i delete the .htaccess, I tried also removing ALL other sites in the www folder, but there's still a rewrite happening from somewhere (do these things cache? i tried clearing browser cache and all that),
BUT
if I put some jibberish in the .htaccess, i get a server error, so I know it is being read!
the other problem is that the rewrite is not passing any variables,
this link works:
http://kurz.local/admin/list/pages.html
but it seems to take to:
http://kurz.local/admin/list.php
instead of
http://kurz.local/admin/list.php?table=pages
online this setup is working, but locally it's not
any ideas ?
i'm really puzzled!
You haven't mentioned if you restarted the server? editing server config files needs a restart, but I believe .htaccess file changes do not need apache server restart.
Your server doc root is:
c:/wamp/www/
Your virtual host doc root is inside the above, I don't think that is allowed.
It should be :
c:/wamp/vhosts/site1root
c:/wamp/vhosts/site2root
etc.
Also see this: https://httpd.apache.org/docs/2.2/vhosts/name-based.html

xampp - mysite.local redirects to xampp folder

I've been battering my head against this all evening and can't see where I'm going wrong. I want to set a host, mysite.local, on xampp and have followed all the instructions, but I keep getting redirected to mysite.local/xampp.
Any ideas where I'm going wrong here? The paths are correct, and I've restarted Apache :)
I edited my hosts file to add:
127.0.0.1 mysite.local
I edited extra/httpd-vhosts.conf:
NameVirtualHost localhost:80
<VirtualHost localhost:80>
ServerName localhost
DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs"
<Directory "/Applications/XAMPP/xamppfiles/htdocs">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order Deny,Allow
Allow from all
</Directory>
</VirtualHost>
<VirtualHost localhost:80>
<Directory "/Applications/XAMPP/xamppfiles/htdocs/wd">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order Deny,Allow
Allow from all
</Directory>
DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs/wd"
ServerName mysite.local
</VirtualHost>
I've just got the very same problem yesterday. Even if the steps you did are correct in a context, you need to do some more tasks ;)
You also need to edit Apach'es httpd.conf referring to your new VirtualHost like this:
# Your great site!
<Directory "/Applications/XAMPP/xamppfiles/htdocs/wd">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
With this alone you'll be able to access http://mysite.local without the redirection to the XAMPP splash screen BUT you'll see the directories of your proyect (at least if you don't have and index in the root folder)
If you need to load a file from a folder (for example /public/index.php) you'll need to use an .htaccess file. Remember this file must be in the folder(s) you want to have control. So for example, an .htaccess file located at the root of your project to redirect to the /public/index.php file you must do it this way:
RewriteEngine On
RewriteBase /
RewriteRule ^.*$ public/index.php [NC,L]
Just remember to use the correct regular expression you need and don't forget to take preventive measures with more security in a production website ;) I wish I've helped you out =)

Common Rewrite Setting For Multiple VHosts

I am running Apache2 with multiple vhosts in the sites-enabled folder, each looks a bit like this:
<VirtualHost *:80>
ServerName site1.com
ServerAlias www.site1.com
DocumentRoot /home/sites/site1/www/
<Directory /home/sites/site/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
<Directory /home/sites/mainsite/www>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
# Provide default favicon.ico and robots.txt using rewrite
RewriteOptions Inherit
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteRule ^/(robots\.txt|favicon\.ico)$ /mainsite_alias$0 [PT,NC,L]
</VirtualHost>
The Rewrite code is common to all vhosts (providing a default favicon.ico/robots.txt) but putting this code into httpd.conf does not seem to have any effect - the rewrite logs show nothing.
How can I make this code common to all vhosts without duplicating the code?
Alternatively - is there a better way of achieving default favicons?
Thanks
You could try a AliasMatch:
AliasMatch ^/(robots\.txt|favicon.ico)$ /home/sites/site1/www/mainsite_alias$0
I am using this
<VirtualHost *:80>
ServerAdmin email_at_isp
DocumentRoot "C:/apache/htdocs"
</VirtualHost>
<VirtualHost *:80>
ServerAdmin admin_at_server_one.com
DocumentRoot "C:/apache/htdocs/server_one.com"
ServerName server_one.com
ErrorLog "logs/server_one.com-error.log"
CustomLog "logs/server_one.com-access.log" common
</VirtualHost>
and I keep rewrite scripts in .htaccess at the root[C:/apache/htdocs]
I hope it helps somehow, if not enoying. lol