How to redirect wildcard subdomain to my domain - web

I would like to redirect wildcard subdomain to my actual domain.
like this (I already have error.example.com)
dsfas.example.com -> error.example.com
but I could not do this after hours of searching. Is there a solution to this.
I am using apache

You can do this by creating a “catch-all” Apache configuration and redirecting to the domain you specify.
Create an Apache configuration file with a name like zzz-catchall.conf (so that it’s the last file alphabetically in the directory) and paste this into the file:
<VirtualHost *:80>
ServerAdmin none#noaddy.net
DocumentRoot /var/www/catch/public
ServerName catch.example.com
ServerAlias *.example.com *.*
DirectoryIndex index.php index.html
ErrorLog ${APACHE_LOG_DIR}/catch-error.log
CustomLog ${APACHE_LOG_DIR}/catch-access.log combined
<Directory /var/www/catch/public>
Options FollowSymLinks
AllowOverride All
Order Allow,Deny
Allow From All
</Directory>
</VirtualHost>
Be sure to change the domain names and directories accordingly.
In the /var/www/catch/public (or whatever) directory, you can set up a redirect a number of ways, but .htaccess would be simple enough:
Redirect 301 / https://error.example.com/
Ensure the virtual host configuration file is enabled, and reload Apache. That should get you going 👍🏻

Related

Url rewriting not working in WAMP Subdomain

I created a Subdomain under my WAMP server for mobile site and it uses IP address as the domain name which is 192.168.106.1
But the issue is that when I try to rewrite a url in my .htaccess file, I doesn't work. And I use a duplicated .htaccess file which works for the localhost
Below is my server configuration for the domain name in my httpd.conf file
<VirtualHost 192.168.106.1>
#LoadModule rewrite_module modules/mod_rewrite.so
# The name to respond to
ServerName m.localhost
# Folder where the files live
DocumentRoot "C:/wamp/www/mobile/"
# A few helpful settings...
<Directory "C:/wamp/www/mobile/">
Allow from all
Order Allow,Deny
# Enables .htaccess files for this site
AllowOverride All
</Directory>
# Apache will look for these two files, in this order, if no file is specified in the URL
DirectoryIndex index.html index.php
</VirtualHost>
I also removed the comment tag on the second line but it still not working.
Please anyone with a solution?
Here is a solution
First make sure you go to your C:/wamp/bin/apache/YOUR APACHE VERSION/conf and open up your httpd.conf file and uncomment this line
#Include conf/extra/httpd-vhosts.conf
So it will look like this
Include conf/extra/httpd-vhosts.conf
Then also open up your host file located in C:/windows/System32/drivers/etc and add this (your ip address to the configuration)
#add the sub-domain name, in this case I use mobile, it can be anything
192.168.106.1 mobile.localhost
192.168.106.1 192.168.106.1
Then finally and most importantly, open up your vhost file in C:/wamp/bin/apache/YOUR APACHE VERSION/conf/extra/httpd-vhosts.conf and add this to the file
<VirtualHost *:80>
DocumentRoot "C:/wamp/www/mobile"
ServerName m.localhost
Options Indexes FollowSymLinks
<Directory "C:/wamp/www/mobile">
AllowOverride All
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
#If you want to allow access from your internal network
# For specific ip addresses add one line per ip address
Allow from 192.168.106.1
# For every ip in the subnet, just use the first 3 numbers of the subnet
#Allow from 192.168.0
</Directory>
</VirtualHost>
Then restart your WAMP server and it works

Virtualhost Document Root changing web root for entire server

I currently have example.com pointing to Server one. I wanted to server example.com from a different directory ( /WebData )
I did this by editing httpd.conf
http://pastebin.com/UjHhRNTX
I this works as desired.
I then found out I needed to add website.org to the server. So I mounted another disk and created a dir called /WebDataWebsite
and created /etc/httpd/conf.d/websiteorg.conf with the following VHost:
http://pastebin.com/GTmqtABf
<VirtualHost *:80>
DocumentRoot "/WebDataWebsite"
ServerName website.org
ServerAlias www.website.org
<Directory "/WebDataWebsite">
Require all granted
</Directory>
</VirtualHost>
For some reason all traffic to example.com and website.org were both directed to index.htm in /WebDataWebsite
What I am doing wrong? How to I make /WebData (in httpd.conf) the default website but filter by servername website.org with the VHost?
You'll probably need to use Alias's for the second site. Have a look at http://httpd.apache.org/docs/2.2/mod/mod_alias.html#alias
It's unlikely that second declaration of the VH is being picked up by apache as it can not deal with two declarations of the same I believe.

redirect from non-www domain name to www using virtualhost not working

I'm having issues redirecting my http://domain.co.uk to http://www.domain.co.uk . I'm pretty new to working with apache and linux so this is what i have done so far. Hopefully there is an obvious mistake that can be fixed easily.
In my attempt to get the redirect working I found a few tutorials saying that i should do it via the virtualhost file so i edited the existing virtual host file that i initially set up for the site in
/etc/apache2/sites-available/domain.co.uk
I have added a new block to the top of this file so it now looks like this:
<VirtualHost *:80>
ServerName domain.co.uk
Redirect permanent / http://www.domain.co.uk/
</VirtualHost>
<VirtualHost *:80>
# Admin email, Server Name (domain name), and any aliases
ServerAdmin admin#domain.co.uk
ServerName www.domain.co.uk
ServerAlias domain.co.uk
# Index file and Document Root (where the public files are located)
DirectoryIndex index.html index.php
DocumentRoot /home/simon/public/domain.co.uk/public/
# Log file locations
LogLevel warn
ErrorLog /home/simon/public/domain.co.uk/log/error.log
CustomLog /home/simon/public/domain.co.uk/log/access.log combined
</VirtualHost>
After editing this file I restarted Apache and tried out the site but http://domain.co.uk is giving me "failed to open the page - cannot reach the server". http://www.domain.co.uk is still working fine.
Is this the right place for this <virtualhost> block? I have seen some mention of putting virtual host info in the httpd.conf file but I haven't been able to find this file in my installation of apache.
Any help would be great.
try this one and restart Apache
<VirtualHost *:80>
ServerName domain.co.uk
ServerAlias *.domain.co.uk
RedirectMatch permanent /(.*) http://www.domain.co.uk/$1
</VirtualHost>

Resolving virtual hosts apache 2

I'm trying to setup my apache server to access certain folders when I type addresses like test1.example.com test2.example.com etc.
So far I read and did many things but with no success yet. I'll be very thankful if you can help me.
So to start I'm using ubuntu 12.10 as my desktop and I've set up apache server there. I've added example.com in hosts resolving to 127.0.0.1. So far no problems. I've enable vhost_alias and mod_rewrite in apache and I'm using this for my virtual server
NameVirtualHost *:80
UseCanonicalName Off
<VirtualHost *:80>
ServerName example.com
ServerAlias *.example.com
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.)?([^\.]+).example.com$
RewriteRule ^(.*) $1 [F]
VirtualDocumentRoot /home/example/server/projects/%1/public_html
<Directory />
Options FollowSymLinks
AllowOverride all
</Directory>
<Directory /home/radoslav/server/projects>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
#log file for this server
CustomLog /var/log/apache2/example.com.log combined
</VirtualHost>
But when I open test.example.com it says that browser can find test.example.com, no matter that I have this directory in the path specified. Just to clear things up apache have permissions to read this directory so it's not this. When I ping example.com from console I get ping but if I ping test.example.com I get error that can not find host. As you can see obviously it's not resolving the adress no matter that I've setup everything correcly.
Any help guys?
You need to add test.example.com and any other hostnames you want to use in the host file. The host file does not supports wildcard.

Problems with Apache Virtual Hosts

I have recently just set up a RHEL based server running two domains. However, I am having difficulty hitting both domains from the browser. My config is:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName domainA.com
ServerAlias domainA.com *.domainA.com
DocumentRoot /home/domainA/public_html
<Directory "/home/domainA/public_html">
allow from all
Options +Indexes
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName domainB.com
ServerAlias domainB.com *.domainB.com
DocumentRoot /home/domainB/public_html
<Directory "/home/domainB/public_html">
allow from all
Options +Indexes
</Directory>
</VirtualHost>
The problem is when I navigate to domainA.com I hit the correct Virtualhost (which is fine), however when I navigate to domainB.com it displays the Apache Test page.
Edit
I have a Firewall between the webserver and the web. I tested the rules governing Domain A and Domain B.
Domain A reaches target and a status 200 is returned.
Domain B reaches target and a status 403 (permission denied) is returned
What you need to do is take a look at sites-enabled and sites-available.
Here's the first entry when Googling: http://www.debian-administration.org/articles/412
Looks reasonable and should help you integrate that.
The problem is that you need separate entries for all the sites you want to run on this apache2. Simple entries in your config file don't do it. Only the first works, the rest is more or less ignored. Creating separate entries with sites-enabled and sites-available is the way to go here.

Resources