Im having some issues with the virtual hosts apache files and htaccess.
I have apache, updated to 2.6 yesterday. I installed 2 virtual domains on it, and disabled the default domain.
All works fine, sites loads fine, no problems there.
The first virtual domain has a htaccess with +50 rewrite conditions and all them work fine!
I tried to add some conditions to the 2nd domain, but the ones that rewrite directories dont work.
This is the condition:
RewriteRule ^user/([a-zA-Z0-9_-]+)$ index.php?username=$1
RewriteRule ^user/([a-zA-Z0-9_-]+)/$ index.php?username=$1
And there, the "sites-available" apache config files for each domain (only the relevant things):
DOMAIN 1:
ServerAdmin webmaster#localhost
ServerName domain1.com
ServerAlias www.domain1.com
DocumentRoot /var/www/domain1.com/public_html
<Directory />
Options FollowSymLinks
AllowOverride ALL
</Directory>
<Directory /var/www/domain1.com/public_html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride ALL
Order allow,deny
allow from all
</Directory>
DOMAIN2:
ServerAdmin webmaster#localhost
ServerName domain2.com
ServerAlias www.domain2.com
DocumentRoot /var/www/domain2.com/public_html
<Directory />
Options FollowSymLinks
AllowOverride ALL
</Directory>
<Directory /var/www/domain2.com/public_html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride ALL
Order allow,deny
allow from all
</Directory>
As you can see, there is no diference between them other than the path to main folder.
I dont understand whats wrong with it.
Why the first domain works perfect and the second one no.
Some things:
A: Any other condition on the domain2 htaccess file works just fine, like redirec simply html to php, or errorhandlers, or just simply redirects to test.
B: I pasted the same rewrite condition in my first domain htaccess file, and it works perfect!
It looks like the apache config file is not working correctly.
Is there anything I must check/change?
I will appreciate any help, and sorry for my english.
Give this a try its tested and working:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^user/([a-z0-9_-]+)/?$ /index.php?username=$1 [NC,L]
I believe the issue is that you have MultiViews enabled, you can also resume your 2 rules into 1 like I have done above.
This should go into the .htaccess of your domain2.
As a side note, you do not need 2 directories directives, you can remove this one:
<Directory />
Options FollowSymLinks
AllowOverride ALL
</Directory>
And keep just:
<Directory "/var/www/domain2.com/public_html">
Options Indexes FollowSymLinks MultiViews
AllowOverride ALL
Order allow,deny
allow from all
</Directory>
Related
I'm using Ubuntu wizzy as my local server and then I set up domain there which are
domain.svr
api.domain.svr
adm.domain.svr
And here is the problem. I've create exactly same configuration for all of them but why only adm.domain.svr doesn't work? It's always response 404 when I goes to http://adm.domain.svr/site/dashboard/ but it's okay when I try http://api.domain.svr/site/dashboard/
Here is my configuration
<VirtualHost *:80>
ServerAdmin localhost#gmail.com
ServerName domain.svr
DocumentRoot /home/shaf/web/domain.dev/frontend/web
<Directory />
Options FollowSymLinks
AllowOverride all
</Directory>
<Directory /home/shaf/web/domain.dev/frontend/web>
Require all granted
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
ErrorLog /home/shaf/log/domain-error.log
LogLevel warn
CustomLog /home/shaf/log/domain-access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerAdmin localhost#gmail.com
ServerName adm.domain.svr
DocumentRoot /home/shaf/web/domain.dev/backend/web
<Directory /home/shaf/web/domain.dev/backend/web>
Require all granted
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
ErrorLog /home/shaf/log/domain-adm-error.log
LogLevel warn
CustomLog /home/shaf/log/domain-adm-access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerAdmin localhost#gmail.com
ServerName api.domain.svr
DocumentRoot /home/shaf/web/domain.dev/api/web
<Directory />
Options FollowSymLinks
AllowOverride all
</Directory>
<Directory /home/shaf/web/domain.dev/api/web>
Require all granted
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
ErrorLog /home/shaf/log/domain-api-error.log
LogLevel warn
CustomLog /home/shaf/log/domain-api-access.log combined
</VirtualHost>
and here is my .htaccess which I placed on every domain web folder
RewriteEngine on
# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule . index.php
Please give me advice about this, I really have no idea.
Your ServerName domain.svr is wrong. Apache can not route it. Try to rename it to adm.domain.svr
I just solve this by duplicate another directory to adm and try it but fail, so I create another 1 host so I have 4 host. 1 is duplicate for adm and it's work perfectly. I still didn't know what happen but seems only that folder didn't read the htaccess and I'm sure of it because I already try to swap sub domain but only adm folder doesn't read the htaccess file.
So here is my conclusion and I don't know this is correct or not but apache has cache of htaccess so I need to hard refresh the apache (only restart apache doesn't work because I already tried it several times and nothing happen) so maybe you need to restart your OS / Server and if you doesn't want it, try my way.
I'm trying to create a RESTful API on a VirtualHost on my Apache 2.4 server (on Ubuntu). I have a php file named dbManager.php which I am using a RewriteRule to look like an api directory. It's working great except for PUT and DELETE commands, which are returning 403 errors. Here's a redacted version of my conf file:
<VirtualHost *>
ServerAdmin onigame#gmail.com
ServerName servername.com
ServerAlias *.servername.com
DirectoryIndex index.html index.php
DocumentRoot /path/to/local/dir/
<Directory />
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
<Limit PUT DELETE>
Require all granted
</Limit>
</Directory>
# RESTful services provided for the fake "api" directory
RewriteEngine on
RewriteRule ^/api/(.*)$ /dbManager.php/$1 [L]
ServerSignature On
AddDefaultCharset utf-8
</VirtualHost>
Well, the PUT and DELETE still aren't working and returning 403. I'm also worried that I don't really want to allow PUT and DELETE everywhere on the directory, but only through the dummy api directory. What's the right way to do this?
I have managed to solve my question, but I don't really understand why it works:
<VirtualHost *>
ServerAdmin onigame#gmail.com
ServerName servername.com
ServerAlias *.servername.com
DirectoryIndex index.html index.php
DocumentRoot /path/to/local/dir/
<Directory />
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</Directory>
<Directory /path/to/local/dir/>
Require all granted
Satisfy All
</Directory>
# RESTful services provided for the fake "api" directory
RewriteEngine on
RewriteRule ^/api/(.*)$ /dbManager.php/$1 [L]
ServerSignature On
AddDefaultCharset utf-8
</VirtualHost>
Best I can figure out, getting a 403 means that it's access being blocked, and not the type of HTTP request (which would result in a 405, not a 403). And the access problem is on the local directory, so it needs a special section for it. But I really don't understand why the two lines I put there make things work. The Require directive, that sort of makes sense. But the Satisfy directive, from what I can tell from the documentation, should default to All.
And yet when I remove either line, it doesn't work.
AS the title says, my rewrite rules does not work when I upload it to my server (Ubuntu LTS). The .htaccess-file is in play, but does nothing.
mod_rewrite is loaded, I've verified that several ways. I tried writing rubbish text in the .htaccess file and got a 500 internal error, so the file seems to be in the loop. The virtualHost configuration has "allowOverride All".
The .htaccess file consists of a series of rewrite rules, such as:
RewriteRule ^webshop$ index.php?page=webshop [QSA]
RewriteRule ^webshop/([0-9]+)$ index.php?page=webshop&catID=$1 [QSA]
On the server I have to virtualhosts, one public server and one testing server. The public server works fine, all rewriterules are similar to above and works. It's the virtualhost for testing that doesn't want to play. One server, one IP, two FQDNs.
Ideas?
EDIT - Here's the VirtualHost config:
<VirtualHost *:80>
ServerAdmin beta#example.com
ServerName beta.example.com
DocumentRoot /var/www/beta/www-root
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/beta/www-root>
AddDefaultCharset utf-8
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from (Two IPs omitted)
</Directory>
<Directory /var/www/temp>
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 /var/log/apache2/error.beta.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/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>
The problem seems to be that there is a folder with the same name as (a part of) the regex. I have a file called "webshop.php", and for some reason the regex ^webshop$ then fails (servers seems to prefer the actual folder/files rather than a local rewrite).
I'm using the symfony framework to do some PHP development, which uses the same code base for separate sites. This requires me to do some htaccess rewriting which is causing me some pain.
The main index page for developer.mysite.com is developer.php. What I'm trying to is rewrite everything going to developer.mysite.com to www.mysite.com/developer.php/$1. However, in the url, I still want it to say developer.mysite.com/$1
The following code I have now redirects and doesn't keep the original url:
RewriteCond %{HTTP_HOST} ^developer\.mysite\.com$ [NC]
RewriteCond %{REQUEST_URI} !\..+$
RewriteRule ^(.*)$ http://www.mysite.com/developer.php/$1 [NC,L]
Are you aliasing developer.mysite.com to mysite.com or does it have it's own public_html (or httpdocs; whatever the webroot is...) folder?
I think the easiest solution would be to point developer.mysite.com to mysite.com on the server so that they share the same public_html folder.
Your main website's front controller would be something like main.php.
The developer subdomain would have its front controller, developer.php.
index.php would look at $_SERVER['SERVER_NAME'] to determine and include the appropriate front controller.
Disclaimer: I'm not familiar with how symfony operates. I'm assuming it has a front controller like a bazillion other frameworks do.
I think that it is better to make separate dir for ur application.
I give an expamle how I realized this task:
<VirtualHost *:80>
DocumentRoot "/path/to/poject/web"
ServerName domain.dev
Alias /sf C:/xampp/php/PEAR/data/symfony/web/sf
<Directory "/path/to/poject/web">
#php_admin_value mbstring.func_overload 7
AllowOverride All
Allow from All
</Directory>
<Directory "C:/xampp/php/PEAR/data/symfony/web/sf">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/path/to/poject/web_developer"
ServerName developer.domain.dev
Alias /sf C:/xampp/php/PEAR/data/symfony/web/sf
<Directory "/path/to/poject/web_developer">
#php_admin_value mbstring.func_overload 7
AllowOverride All
Allow from All
</Directory>
<Directory "C:/xampp/php/PEAR/data/symfony/web/sf">
AllowOverride All
Allow from All
</Directory>
Alias /css /path/to/poject/web/css
<Directory "/path/to/poject/web/css">
AllowOverride All
Allow from All
</Directory>
Alias /images /path/to/poject/web/images
<Directory "/path/to/poject/web/images">
AllowOverride All
Allow from All
</Directory>
Alias /js /path/to/poject/web/js
<Directory "/path/to/poject/web/js">
AllowOverride All
Allow from All
</Directory>
Alias /sfDoctrinePlugin /path/to/poject/web/sfDoctrinePlugin
<Directory "/path/to/poject/web/sfDoctrinePlugin">
AllowOverride All
Allow from All
</Directory>
Alias /sfFormExtraPlugin /path/to/poject/web/sfFormExtraPlugin
<Directory "/path/to/poject/web/sfFormExtraPlugin">
AllowOverride All
Allow from All
</Directory>
Alias /uploads /path/to/poject/web/uploads
<Directory "/path/to/poject/web/uploads">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
web_developer dir is usual web dir of sf1.4 project
I can currently run either Django through mod_wsgi or PHP on my Apache server.
My Django projects run at: http://localhost and source is at C:/django_proj
My PHP projects run at: http://php.localhost and source is at C:/web
If I turn both on, php.localhost and localhost go to the Django project. I've already set them up through Apache virtual hosts.
Here are some relevant lines in httpd.conf:
DocumentRoot "C:/web"
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
<Directory "C:/web">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
<Directory "C:/django_proj">
Order allow,deny
Allow from all
</Directory>
Include "C:/django_proj/apache/apache_django_wsgi.conf"
The relevant lines in apache_django_wsgi.conf is:
WSGIScriptAlias / "C:/django_proj/apache/proj.wsgi"
<Directory "C:/django_proj/apache">
Order allow,deny
Allow from all
</Directory>
Inside httpd-vhosts.conf:
<Directory C:/web>
Order Deny,Allow
Allow from all
</Directory>
<Directory C:/django_proj>
Order Deny,Allow
Allow from all
</Directory>
<VirtualHost *:80>
DocumentRoot "C:/django_proj"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/web"
ServerName php.localhost
</VirtualHost>
My PHP project is current inaccessible. Does anyone have any ideas what I'm missing?
I run dozens of mod_wsgi/Django sites, PHP sites, and a Rails site with a single Apache.
It's mostly done using virtual hosts but I have some that are running both on the same domain.
You just need to put your WSGIScriptAlias /... after any other Location/Alias directives.
Lets say, for example, I want to run phpMyAdmin on the same domain as a Django site. The config would look something like this:
Alias /phpmyadmin /full/path/to/phpmyadmin/
<Directory /full/path/to/phpmyadmin>
Options -Indexes
...etc...
</Directory>
WSGIScriptAlias / /full/path/to/django/project/app.wsgi
<Directory /full/path/to/django/project>
Options +ExecCGI
...etc...
</Directory>
Edit:
Your configuration should look something like this:
<VirtualHost *:80>
DocumentRoot "C:/django_proj"
ServerName localhost
WSGIScriptAlias / "C:/django_proj/apache/proj.wsgi"
<Directory "C:/django_proj/apache">
Options +ExecCGI
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/web"
ServerName php.localhost
Alias / C:/web
<Directory C:/web>
Options Indexes FollowSymLinks
AllowOverride None
Order Deny,Allow
Allow from all
</Directory>
</VirtualHost>
You don't need those <Directory> directives in http.conf... do all your configuration in the Virtual hosts.
Also, completely get rid of the <Directory /> block.
Your WSGIScriptAlias / ... directive is telling Apache that everything request starting with "/" should get fed through Django's WSGI handler. If you changed that to read WSGIScriptAlias /django-proj/ ... instead, only requests starting with "/django-proj" would get passed into Django.
An alternative would be to start setting up virtual hosts for each project. This way you could configure Apache to put each project at the / of it's own domain, and you wouldn't need to worry about the configuration for one project affecting one of your other projects.
I had the same problem.
Try removing this block <Directory /> in httpd-conf.
Include httpd-vhost.conf and and try puting my WSGIScriptAlias / "/somewhere/file.wsgi" in virtual host section of httpd-vhosts which listens to port 80.
I would like to add that if you are using Apache ProxyPass, it's possible to deny certain URL patterns so that it falls to mod_php.
ProxyPass /wordpress !
<Location /wordpress>
Require all granted
</Location>