Apache2, setup dynamic subdomains on localhost - .htaccess

Simple question how?
Now I have such enabled host
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName git.land
DocumentRoot /home/sergey/public_html/git.land/public_html
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /home/sergey/public_html/git.land/public_html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
And added rule in hosts
127.0.0.1 git.land
When I enter on "http://git.land" it show proper direction. But when I try to get in "http://some.git.land" is stucks. Thinks a lot and then redirect on prev. page (without subdomain).
I want add subdomains to localhost for testing but I don't know what should I use for it. Base things I knew, I tried but it gives nothing.
Also can I (maybe) somehow change it from .htaccess (I searched around and found people use them to get subdomains name without any configuration in hosts).

Problem solved by this config file
<VirtualHost *:80>
DocumentRoot /home/sergey/public_html/git.land/public_html
ServerName other.land
ServerAlias *.land
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName land
DocumentRoot /home/sergey/public_html/git.land/public_html
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /home/sergey/public_html/git.land/public_html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit, alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
It works ONLY when all cases (I mean subdomains) setup in hosts.

Related

.htaccess not working on new Debian 8 setup

So I've just set up Debian 8 on a new server, enabled a2enmod and restarted. However my links aren't working, and when I try to go in to sites-available and default I have this:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
I'm trying to change None to all, however this is still not working and is giving an error below:
Not Found
The requested URL /tos was not found on this server.
Can anyone help out on this please?
When I change them to All instead of None, it just reloads the homepage?
What if you change AllowOverride None to AllowOverride All ?
I know this is 20 months late, but in case someone else looks for an answer here, maybe you just need to restart the server.
something like:
sudo service apache2 graceful

mod_rewrite not reading htaccess

I'm trying to enable mod_rewrite on server. My web is located in folder /data/web/new-domovreality.sk/web. There are .htacces and index.php files in this folder.
My current
etc/apache2/sites-available/default
<VirtualHost *:80>
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
<Directory /data/web/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride All
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
I've read I think every instructions to enable it, but I'm not able to. Can someonehelp me? I'm doing this first time. Thanks
When I use phpinfo() there is mod_rewrite enabled.
So, the solution was to change the * to IP address, so in final
<VirtualHost *:80>
looks like this:
<VirtualHost 37.9.170.195:80>

404 not found after activating Joomla 2.5 URL rewriting at localhost

I have a copy of my website at localhost at:
/var/www/vhosts/mysite.com/httpdocs
This is my /etc/apache2/sites-available/mysite
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/vhosts/mysite.com/httpdocs
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
I've copied htaccess.txt to .htaccess. When I activate friendly URL and URL rewriting, I get 404 errors.
I've uncommented this lines in .htaccess, but still does not work:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
I also tried to change rewritebase to
RewriteBase /mysite
with no luck.
What I'm doing wrong?
No sure if this is the issue you are experiencing, but I have experienced that rewriting does not work well on "localhost". Try and change your hosts file to say
127.0.0.1 mysite.local
And then access it on that url.
Not sure if that will work but it is worth a try.
Solved!
I had a conflict with different entries in /etc/apache2/sites-available.
When I create a new site at localhost, I copy default to mysite, and modify the mysite file to point to it's DocumentRoot.
I don't know exactly why, but if I disable default site:
sudo a2dissite default
it works.
Maybe this does'nt solve the question, but I prefer to issue another question more specific to this problem, because I've tested and it's related to different sites enabled and one or more with RewriteEngine enabled.

Enable htaccess error on Ubuntu 12.04 with Apache2

I tried to enable htaccess. I changed:
<Directory /var/www/abc.biz/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
To:
<Directory /var/www/abc.biz/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
But I'm getting 500 (Internal Server) error. Why?
Here is my /etc/apache2/sites-available/default file:
<VirtualHost *:80>
ServerAdmin admin#abc.biz
DocumentRoot /var/www/abc.biz
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/abc.biz/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
I think you need to change this part of your /etc/apache2/sites-available/default
DocumentRoot /var/www/abc.biz
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/abc.biz/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
to
DocumentRoot /var/www/abc.biz
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/abc.biz/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
Because at first <Directory /> AllowOverride All you allow to override settings with your .htaccess file for the whole apache, but also you need to change it at <Directory /var/www/abc.biz/> AllowOverride All for your specific host directory, where your web site is placed.
Also you should check .htaccess files placed in your /var/www/abc.biz directory to be correctly writen, because when you enable .htaccess files to override global apache settings wrong .htaccess file causes such error.

htaccess with virtualhost not working

I have a local dev Debx64 machine with a number of virtualhosts configured.
the primary URL is set as
<VirtualHost *:80>
ServerAdmin webmaster#blah.com
ServerName blah.com
ServerAlias blah.com
DocumentRoot /home/blah/v1.blah.com
<Directory /home/blah/v1.blah.com/>
AllowOverride All
Order allow,deny
allow from all
</Directory>
AccessFileName .htaccess
ErrorLog /home/blah/blah_logs/v1.blah.com.in-error_log
CustomLog /home/blah/blah_logs/v1.blah.com.in-access_log common
</VirtualHost>
and that redirects to the primary operating VH
<VirtualHost *:80>
ServerAdmin webmaster#blah.com
ServerName v1.blah.com
ServerAlias v1.blah.com
DocumentRoot /home/blah/v1.blah.com
<Directory /home/blah/v1.blah.com/>
AllowOverride All
Order allow,deny
allow from all
</Directory>
AccessFileName .htaccess
ErrorLog /home/blah/blah_logs/v1.blah.com.in-error_log
CustomLog /home/blah/blah_logs/v1.blah.com.in-access_log common
</VirtualHost>
I have a .htaccess set up on v1.blah.com to parse .html as .php
Options +ExecCGI
AddHandler php-fcgi .php .html
Action php-cgi /home/php5-fcgi
<FilesMatch "^php5?\.(ini|cgi)$">
Order Deny,Allow
Deny from All
Allow from env=REDIRECT_STATUS
</FilesMatch>
This works fine if I access the URL as v1.blah.com, however if I access it as blah.com the .htaccess is not invoked and the .html is served as normal.
What Am I missing? is there something in php.ini that needs to be changed?
Is there a particular reason why you need to have two separate entries for your hosts? Seeing as they both use the same Log Files, and DocumentRoot, could you not add blah.com to the list of ServerAlias' ?
So you would end up with the following configuration below:
<VirtualHost *:80>
ServerAdmin webmaster#blah.com
ServerName v1.blah.com
ServerAlias v1.blah.com blah.com
DocumentRoot /home/blah/v1.blah.com
<Directory /home/blah/v1.blah.com/>
AllowOverride All
Order allow,deny
allow from all
</Directory>
AccessFileName .htaccess
ErrorLog /home/blah/blah_logs/v1.blah.com.in-error_log
CustomLog /home/blah/blah_logs/v1.blah.com.in-access_log common
</VirtualHost>

Resources