Redirecting client to single domain name.

Here is a problem where a site is hosted under different virtual hosts with different domain names.

Example:
VirtualHost1 is setup for http://www.example.net
VirtualHost2 is setup for http://www.example.com

And, we want to redirect to or show only http://www.example.com domain to our clients.

Then, make some changes as below in main apache config file that is httpd.conf:

 <VirtualHost *:80>
  ServerName www.example.net
  ServerAlias example.com
  Redirect permanent / http://www.example.com/
 </VirtualHost>
<VirtualHost *:80>
 ServerName www.example.com
 DocumentRoot /usr/local/apache/htdocs
</VirtualHost>

Redirect Link to Mobile Website using .htaccess

Just add the following code in your .htaccess file


RewriteEngine on
RewriteBase /

# prevent looping
RewriteCond %{HTTP_HOST} !^m.mysite.com$

# if the browser accepts these mime-types, it's definitely mobile, or pretending to be
RewriteCond %{HTTP_ACCEPT} "text/vnd.wap.wml|application/vnd.wap.xhtml+xml" [NC,OR]

# a bunch of user agent tests
RewriteCond %{HTTP_USER_AGENT} "sony|symbian|nokia|samsung|mobile|windows ce|epoc|opera" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "mini|nitro|j2me|midp-|cldc-|netfront|mot|up.browser|up.link|audiovox"[NC,OR]
RewriteCond %{HTTP_USER_AGENT} "blackberry|ericsson,|panasonic|philips|sanyo|sharp|sie-"[NC,OR]
RewriteCond %{HTTP_USER_AGENT} "portalmmm|blazer|avantgo|danger|palm|series60|palmsource|pocketpc"[NC,OR]
RewriteCond %{HTTP_USER_AGENT} "smartphone|rover|ipaq|au-mic,|alcatel|ericy|vodafone/|wap1.|wap2.|iPhone|android"[NC]

# rewrite rules here
RewriteRule .? http://m.mysite.com%{REQUEST_URI}  [L,R=302]