I am using apache2 + tomcat on ubuntu 10.4. I am running on tomcat server that has webapps listening on 8080
"http://internal:8080/dir/name-privatewebapp/"
"http://internal:8080/dir/name-publicwebapp/"
External facing Apache server is proxying requests for the domain.
I would like to remap "subdomain" to "domain.com/subdomain" , so any other requests would be proxied to the appropriate path / webapp
web.john-doe.domain.com ---> www.domain.com/web/john-doe
http://www.john-doe.com ---> www.domain.com/web/john-doe
http://www.foo-bar.com ---> www.domain.com/web/foo-bar
I couldnt make it work with mod_rewrite alone. I have been looking into
mod_proxy, mod_proxy_ajp, and mod_rewrite
I would like the server to
Grab the subdomain from the domain
Make sure the subdomain is not www, w or ww
Check if the directory actually exists on "www.domain.com" before rewrite
if the directory doesnt exist it stays as wild domain
Finally, if the directory exist the actual rewrite
I checked several links and studied tutorials on http://www.askapache.com/htaccess/crazy-advanced-mod_rewrite-tutorial.html
It is without success.
I followed this
illumin-it.servehttp.com/wordpress/2012/01/redirecting-to-as-using-apache/
with a bit of success.
However, I would like to the server to do it on the fly through rewrites and proxies without editing the vhost for every subdomain.
here is my updated vhost file
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName www.domain.com
ServerAlias www.domain.com domain.com *.domain.com
RedirectPermanent / http://www.domain.com
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
<IfModule mod_rewrite.c>
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /
# Prevent looping this rule
# RewriteCond %{ENV:REDIRECT_STATUS} !200
# RewriteCond %{HTTP_HOST} !www.domain.com$ [NC]
# RewriteCond %{HTTP_HOST} ^(www\.)?([a-z0-9.-]+).domain.com$ [NC]
# RewriteRule (.*) /%2/$1 [L]
# change the "." in the path to "/"
# RewriteRule ^(.*)\.(.*)/(.*)$ /$1/$2/$3 [L]
#redirect domain.com to www.domain.com
RewriteCond %{HTTP_HOST} !^domain\.com$ [NC]
RewriteRule ^ http://www.domain.com%{REQUEST_URI} [R=301,NC]
</IfModule>
</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.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>
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
# ErrorLog /var/log/apache2/webapp_error.log
# LogLevel warn
# CustomLog /var/log/apache2/webapp_access.log combined
ProxyPass / ajp://localhost:8009/
ProxyPassReverse / ajp://localhost:8009/
# ProxyPass /user/ http://localhost:8080/user/privatewebapp/
# ProxyPassReverse /user/ http://localhost:8080/user/privatewebapp/
#
# ProxyPass /publicweb/ http://localhost:8080/dir/publicwebapp/
# ProxyPassReverse /publicweb/ http://localhost:8080/dir/publicwebapp/
#
# ProxyPass / http://localhost:8080/dir/publicwebapp/
# ProxyPassReverse / http://localhost:8080/dir/publicwebapp/
ServerName www.domain2.com
ProxyRequests Off
ProxyPreserveHost On
RewriteEngine On
RewriteCond %{HTTP_HOST} ^dir/publicwebapp$ [NC]
RewriteRule ^(.*)$ http://www.domain2.com/$1 [R=301,L]
<Location / >
Order deny,allow
Allow from all
RedirectMatch ^/$ /dir/publicwebapp/
ProxyPass ajp://localhost:8009/
ProxyPassReverse ajp://localhost:8009/
</Location>
</VirtualHost>
I also tried...
http://httpd.apache.org/docs/2.0/rewrite/rewrite_guide.html
assuming www.username.host.com/anypath internally maps to www.host.com/home/username/anypath
As the site's applications created with Java servers, I believe mod_rewrite alone doesnt work.
Virtual User Hosts
RewriteCond %{HTTP_HOST} ^www\.[^.]+\.host\.com$
RewriteRule ^(.+) %{HTTP_HOST}$1 [C]
RewriteRule ^www\.([^.]+)\.host\.com(.*) /home/$1$2
Your first set of rules:
#redirect domain.com to www.domain.com
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteRule .+ http://www.domain.com%{REQUEST_URI} [R=301,NC]
Is superceding any subdomain you have if you don't have an empty request. The second set of rules comes close to what you want. But they loop and they don't turn multiple subdomain entries into directory paths, so try putting this set of rules first:
# Prevent looping this rule
RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteCond %{HTTP_HOST} !www.domain.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([a-z0-9.-]+).domain.com$ [NC]
RewriteRule (.*) /%2/$1 [L]
# change the "." in the path to "/"
RewriteRule ^(.*)\.(.*)/(.*)$ /$1/$2/$3 [L]
Then change your "non-www to www" rule to this (and place after the above rules):
#redirect domain.com to www.domain.com
RewriteCond %{HTTP_HOST} !^domain\.com$ [NC]
RewriteRule ^ http://www.domain.com%{REQUEST_URI} [R=301,NC]
In similar cases I usualy put somethin like this to .htaccess in webroot (/var/www/.htaccess):
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} subdomain1.domain.com
RewriteCond %{REQUEST_URI} !^/subdomain1
RewriteRule ^(.*)$ one/$1 [L]
RewriteCond %{HTTP_HOST} subdomain2.domain.com
RewriteCond %{REQUEST_URI} !^/subdomain2
RewriteRule ^(.*)$ two/$1 [L]
RewriteRule ^$ / [L]
RewriteRule (.*) /$1 [L]
</IfModule>
so I have
subdomain1.servername.com -> /var/www/subdomain1
subdomain2.servername.com -> /var/www/subdomain2
servername.com -> /var/www
Maybe this will help you?
Related
I'm building webapp on Ubuntu + Apache2 with wildcard SSL certificates
My goal is to set up functioning project on 1st level domain project.app as well as several subdomains marketplace.project.app & partners.project.app
All of the project files are under the same directory:
www/project/
subdomains accessible via laravel router:
Route::domain('marketplace.project.app')->group(function () {
Route::view('','pages.marketplace');
});
serverside DNS records:
A | project.app | 127.0.0.1
A | *.project.app | 127.0.0.1
/sites-available/default-ssl.conf:
ServerName project.app
ServerAlias *.project.app
DocumentRoot /var/www/project/public
<Directory /var/www/project>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
.htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^127\.0\.0\.1
RewriteRule (.*) https://project.app/$1 [R=301,L]
All of the wildacrd subdomains e.g. bbb.project.app work flawlessly, but upon accessing app in browser via 1st level project.app apache does not render index.php file.
Is the setup I'm thriving for feasible in apache or should I switch to Ngnix?
Just to alert, You do not really need to use htaccess rules once you use apache2, ybecause "blahblahblah.conf" can handle htaccess rules.
To handle multiple domains and including htaccess rules with it, you can do the following (working example):
<VirtualHost *:80>
ServerName example.com
ServerAlias foo.example.com bar.example.com others.example.com
DocumentRoot "/var/www/laravel_folder/public"
<Directory /var/www/laravel_folder/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
RewriteEngine on
RewriteCond %{SERVER_NAME} =example.com [or]
RewriteCond %{SERVER_NAME} =www.example.com [or]
RewriteCond %{SERVER_NAME} =foo.example.com [or]
RewriteCond %{SERVER_NAME} =www.foo.example.com [or]
RewriteCond %{SERVER_NAME} =bar.example.com [or]
RewriteCond %{SERVER_NAME} =www.bar.example.com [or]
RewriteCond %{SERVER_NAME} =others.example.com [or]
RewriteCond %{SERVER_NAME} =www.others.example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
I have windows server and have domain of godaddy. I took SSL from godaddy and apply on my server. My domain gets secure by SSL but problem come when, i redirect from https://www.example.com and logged in it shows dashboard but when i change url to https://example.com it redirect me to login page.
Here is my VHOST file
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot "C:/mcpluat/xampp/htdocs/project/public"
ServerName www.example.com
ServerAlias example.com
RewriteEngine on
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/ [R,L]
<Directory "C:/mcpluat/xampp/htdocs/project/public">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
.HTACCESS file
Options -MultiViews -Indexes
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Everything is working perfectly but why it is treating www.example.com and example.com a different domain
Thanks in advance
Is there a specific RewriteRule that would work for Magento and convert
http://<domainname>/index.php/<filename>
into
http://<domainname>/<filename>
According to phpinfo(), Loaded Modules lists mod_rewrite , so it appears to be enabled.
Here is the relevant section from .htaccess
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_URI} !^/(media|skin|js)/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php [L]
</IfModule>
Any suggestions?
So it turns out that it wasn't a missing mod_rewrite rule. I fixed it by inserting the Directory section below into /etc/apache2/sites-available/dev.magecom.local.conf (The Directory section didn't exist at all in the previous version).
<VirtualHost *:80>
ServerName dev.magecom.local
ServerAlias www.dev.magecom.local
DocumentRoot /var/www/sites/dev.magecom.local/public_html/
<Directory /var/www/sites/dev.magecom.local/public_html/>
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
I'm very new to apache. I read and read docs, turn all conf files I found, but ...
While I'm root on the webserver, I read that in order to optimize apache2, it is not a good idea to use .htaccess files (http://httpd.apache.org/docs/current/howto/htaccess.html).
OK, I read a lot of howtos about url_rewriting and htacess. I tried this code into my www.site.com virtualhost file :
<VirtualHost *:80>
ServerName site.com
ServerAlias www.site.com
ServerAdmin webmaster#site.com
DocumentRoot /var/www/www.site.com
RewriteEngine On
<directory />
RewriteBase /var/www/www.site.com/
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_URI} !^/index\.php
RewriteCond %{REQUEST_URI} /component/|(/[^.]*|\.(php|html?|feed|$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Please note that RewriteBase has been tested with DocumentRoot value and '/', and that all the RewriteCond come form std_htaccess of latest Joomla! source code.
Apache2 launches well, the site is viewed online with no error, but the rewrite is not working as joomla SEF is not working :(
I'm totaly lost ... again ... and I need your help guys !
Ok, the correct way is
<directory /var/www/www.site.com/>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_URI} !^/index\.php
RewriteCond %{REQUEST_URI} /component/|(/[^.]*|\.(php|html?|feed|pdf|vcf|raw))$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]
Options FollowSymLinks
AllowOverride None
</Directory>
Below you will find my current vHost entry that I am using for a site that I currently have under development. This vHost entry works fine when I have it on my local machine, but when I push my code to my staging server that is running this same vHost record I receive a 500 Internal Server error.
The machine I'm running this vHost on is running Apache 2.2.9 (Debian).
<VirtualHost 206.217.196.61:80>
SuExecUserGroup 13labs 13labs
ServerAdmin aellis#1three.com
ServerName admin.13labs.net
ServerAlias admin.13labs.net
DirectoryIndex index.php
DocumentRoot /var/www/13labs.net/html/admin/
ErrorLog /var/www/13labs.net/logs/error.log
# Hide .svn Directories
<DirectoryMatch "\.svn">
Order deny,allow
deny from all
</DirectoryMatch>
# FastCGI
Alias /fcgi-bin/ /var/www/13labs.net/fcgi-bin/
AddHandler php-fastcgi .php
AddType application/x-httpd-php .php
Action php-fastcgi /fcgi-bin/admin-php.fcgi
<Directory /var/www/13labs.net/fcgi-bin/>
SetHandler fcgid-script
AllowOverride None
Options -Indexes +ExecCGI -FollowSymlinks -SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
<Directory /var/www/13labs.net/html/admin/>
AllowOverride None
Options -Indexes -FollowSymlinks -SymLinksIfOwnerMatch
FileETag All
</Directory>
# Rewrite Logic
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !\.(gif|jpe?g|png|js|css|swf|php|ico|txt|pdf)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^/(.+)$ /index.php/$1 [PT,QSA,L]
Thanks for any help that you can provide.
Best regards,
Andrew
After many trial and errors I have found that the working RewriteRule needs to be the following:
RewriteRule ^.*$ /index.php$1 [PT,QSA,L]
Then in PHP I need to be using $_SERVER['REQUEST_URI'] instead of $_SERVER['PATH_INFO'] to make sure my PHP script see the passed in URI.