If you want to be able to redirect blah.domain.com to domain.com/blah/ so that blah.domain.com is shown in the address bar here’s a quick and dirty how to:
First off if you want any subdomain to be able to be redirected first you need to set-up your DNS correctly. In my case this was as simple as going to the people that host my domain and adding an A record with the wildcard * that pointed to my server’s ip address. Bear in mind your DNS settings may take a while to work so be patient. Before you proceed you should check that anything.domain.com resolves to the ip address of your server. You can check this by running:
ping iloveapache.domain.com
The next step is to set-up the virtual host to respond to the wildcard subdomains. In the case of plesk you have to set-up a vhost.conf file but on any other apache installation you can just edit httpd.conf and look for the that corresponds to your site. If you are using Plesk you will need to ssh in to your server and create a vhost.conf file if it doesn’t already exist here where is your domain:
/var/www/vhosts//conf/vhost.conf
Open that file with the command line editor of your choice and add the following directives:
ServerAlias *.domain.com
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.* [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.domain\.com
RewriteCond /var/www/vhosts/domain.com/httpdocs/%1 -d
RewriteRule ^(.*) /%1/$1 [L]
Substitute domain.com for your domain. Now here’s a quick walkthrough how these rules work. The first line ServerAlias *.domain.com tells apache to accept anysubdomain.domain.com.
Next the rewrite rules work as follows:
1. The first line of mod_rewrite !^www.* only matches urls that don’t begin with www. You don’t want to redirect www.domain.com to www.domain.com/www/ do you? Note: you could add additional lines like these to prevent re-writing other subdomains like secure.domain.com if that should not be redirected to domain.com/secure/
2. The second line ^([^\.]+)\.*$ captures into a backreference anything that doesn’t have a period e.g. the subdomain. The plus makes sure that there is at least one character that matches.
3. The next condition checked is that the directory captured into the backreference does actually exist hence the -d.
4. This last line ^(.*) /%1/$1 [L] takes the requested path and dumps it into a back reference and then rewrites it to point to the a directory (the subdomain backreference captured in the Rewrite conditions above) . In other words %1 is the subdomain backreference and $1 is the path backreference (that captured by .*). The important thing to rember is you can refer to backreferences in rewriteCond lines with % and backreferences in rewriteRules with $. Lastly the [L] (last) means doen’t further rewrite this URL. Note: You might want to leave this out if you are doing any subsequent rewrites, be sure to test what you have set-up thoroughly!!!
And then whether are using Plesk or not you need to restart apache e.g:
service httpd restart
Share or Bookmark This Post With :
In this tutorial, apache2 server is installed through wamp server for PHP under c:/wamp/Apache2.
Download and install
- Java 1.5 JDK JDK 5.0 Update 7
- Tomcat 5.5.17 apache-tomcat-5.5.17.tar.gz
- mod_jk 1.2.18 mod_jk-apache-2.x.xx.so
Configuration
- Java JDK path : C:\jdk1.5.0_07
- Apache path : C:\wamp\Apache2
- Tomcat path : C:\tomcat5
- JSP/Servlet webroot (via Apache2/mod_jk) : C:\tomcat5\webapps
- JSP/Servlet webroot (via native Tomcat server, port 8080) : C:\tomcat5\webapps
- Access JSP/Servlet pages via Apache2/mod_jk : http://localhost/[jkmount-mapped url of your webapp]
- Access native Tomcat server : http://localhost:8080/
Unpack and place Tomcat5 and mod_jk
- Unpack file apache-tomcat-5.5.17.tar.gz under directory C:\
- Rename directory C:\apache-tomcat-5.5.17 to C:\tomcat5
- Rename file mod_jk-apache-2.x.xx.so to mod_jk.so, and place under directory C:\wamp\Apache2\modules. In wamp its already compiled and installed under c:/wamp/Apache2/modules
Configuration and Setup
- How to set environment variable on windows+unix
- Create empty file C:\wamp\Apache2\conf\workers.properties, insert code…
workers.java_home=C:/jdk1.5.0_07
ps=\
# Define worker 'example'
worker.list=example,worker1,worker2,worker3
# Set properties for worker 'example' (ajp13)
worker.example.type=ajp13
worker.example.host=localhost
worker.example.port=8009
worker.example.cachesize=10
worker.example.cache_timeout=600
worker.example.socket_keepalive=1
worker.example.recycle_timeout=300
# Set properties for worker1
worker.worker1.type=ajp13
worker.worker1.host=localhost
worker.worker1.port=8109
# Set properties for worker2
worker.worker2.type=ajp13
worker.worker2.host=localhost
worker.worker2.port=8209
# Set properties for worker3
worker.worker3.type=ajp13
worker.worker3.host=localhost
worker.worker3.port=8309
Edit file C:\wamp\Apache2\conf\httpd.conf, insert code
JkWorkersFile conf/workers.properties
JkLogFile logs/mod_jk.log
JkLogLevel error
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
JkRequestLogFormat "%w %V %T"
Alias /jsp-examples "C:/tomcat5/webapps/jsp-examples/"
<directory>
Options Indexes +FollowSymLinks
AllowOverride None
Allow from all
</directory>
Alias /servlets-examples "C:/tomcat5/webapps/servlets-examples/"
<directory>
Options Indexes +FollowSymLinks
AllowOverride None
Allow from all
</directory>
<location /*/WEB-INF/*>
AllowOverride None
deny from all
</location>
JkMount /jsp-examples/*.jsp example
JkMount /servlets-examples/* example
</IfModule>
If you dont want to mount some files or directories, you can exclude using JkUnMount
Install and Start Tomcat
Tomcat can be installed as a Service or started as a Standalone Console application. Note to make sure that Apache has been started at this point.
Share or Bookmark This Post With :
To change Host Name Locally modify hosts file which is located under below specified path and add new hostname whatever you like for testing locally.
C:\WINDOWS\system32\drivers\etc\hosts
To modify URL and remove webapps name from url you have to do below steps.
Create below specified file under specified path and insert that code.
This for default localhost application.
conf/Catalina/localhost/ROOT.xml
<Context displayName="localhost" docBase="" path=""
workDir="work/Catalina/localhost/_">
</Context>
For your custom application you have to add code as specified below.
Where $host is your custom web application.
Add a configuration file for the host
mkdir conf/Catalina/$host
cat >conf/Catalina/$host/ROOT.xml
<?xml version='1.0' encoding='utf-8'?>
<Context displayName="$host" docBase="" path=""
workDir="work/Catalina/$host/_">
</Context>
Main step is to add ROOT folder under your webapps/$host folder like specified below
$tomcatdir/webapps/$host/ROOT/all the files
Next You have to modify server.xml file to add context paths and host
Example:
<Server port="8005" shutdown="SHUTDOWN">
<!– Comment these entries out to disable JMX MBeans support used for the
administration web application –>
<Listener className="org.apache.catalina.core.AprLifecycleListener" />
<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.storeconfig.StoreConfigLifecycleListener"/>
<!– Global JNDI resources –>
<GlobalNamingResources>
<!– Test entry for demonstration purposes –>
<Environment name="simpleValue" type="java.lang.Integer" value="30"/>
<!– Editable user database that can also be used by
UserDatabaseRealm to authenticate users –>
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>
<!– Define the Tomcat Stand-Alone Service –>
<Service name="Catalina">
<!– Define a non-SSL HTTP/1.1 Connector on port 8080 –>
<Connector port="8080" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true" />
<!– Note : To disable connection timeouts, set connectionTimeout value
to 0 –>
<!– Define an AJP 1.3 Connector on port 8009 –>
<Connector port="8009"
enableLookups="false" redirectPort="8443" protocol="AJP/1.3" />
<!– Define the top level container in our container hierarchy –>
<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
<Context path="" docBase="webapps/ca"
debug="5" reloadable="true" crossContext="true">
<Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="database_user" password="database_password" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/beta2?autoReconnect=true"/>
</Context>
<Context path="" docBase="webapps/app1" debug="5" reloadable="true" crossContext="true"></Context>
<Host name="localhost" appBase="webapps/app2"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
</Host>
<Host name="testdomain" debug="0" appBase="C:/tomcat-5.5/webapps/app1" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
<Logger className="org.apache.catalina.logger.FileLogger"
directory="logs" prefix="testdomain_log." suffix=".txt" timestamp="true"/>
<Alias>testdomain.com</Alias>
</Host>
</Engine>
</Service>
</Server>
For as many applications you have to apply
Share or Bookmark This Post With :
- dotProject – the Open Source Project Managem...
- The jQuery Form Plugin
- DocVerse has officially been acquired by Google
- HDGraph – a free tool for Windows to draw mu...
- RandomClass jQuery Plugin
- Paparazzi – a small utility for Mac OS X to ...
- Blocking SPAM using Postfix header_checks and Spam...
- Facebook, Paypal team up for virtual goods payment
- Opera Mini – the next generation mobile brow...
- XML/SWF Charts – powerful tool to create att...
- Send emails using PHPMailer an...
- Firefox Addons Essential for S...
- Free SEO Tools From SEOMoz.org...
- URL Rewriting for PHP Web Appl...
- Multiple Instances of Tomcat w...
- Apache 2.x + Tomcat 4.x + Load...
- Pagination in JSP/Java
- PHP – Mysql Open Source ...
- java.lang.OutOfMemoryError: Ja...
- HOW TO Subversion+Apache on Fe...





