Solved

Any subdomain works!!

Posted on 2010-08-17
7
351 Views
Last Modified: 2013-12-13
Hi,

I noticed that any subdomain can access my website index .. why is that and how I can disable that?

For example : If anyone typed dsfsfsd.mywebsite.com it will access the index page and it will not redirect to www.mywebsite.com or give an 404 error?


Thank you so much for the ehlp.
0
Comment
Question by:Dido123
7 Comments
 
LVL 4

Expert Comment

by:philkeene
ID: 33459506
Do a header redirect if the $_SERVER['HTTP_HOST'] variable doesn't match www.mywebsite.com.

Let me know if you need assistance with that.
0
 
LVL 11

Accepted Solution

by:
Pieter Jordaan earned 500 total points
ID: 33459541
Hi

You can either change the DNS:
Your DNS server is configured to forward *.mywebsite.com to your IP address.
You can replace *.mywebsite.com with www.mywebsite.com to only forward the www record.

And/Or

Change your web server settings.
Your apache default DocumentRoot points to your web folder, so any address will load the default index file.
Create a virtual host for domain www.mywebsite.com and point it's DocumentRoot to your current web root folder, then change the default one to a different folder. You can create an empty index.html file in it, to give a blank page.

You can find examples on the Virtual host configuration here:
http://www.debian-administration.org/articles/412

The manual: http://httpd.apache.org/docs/2.2/vhosts/

I hope that helps.


0
 
LVL 6

Expert Comment

by:merwetta1
ID: 33461006
philkeene's solution will work, but you will probably want to add the code to all your pages, and all your pages would have to be PHP in order to enforce the "no stray subdomains" rule.

Bitfreeze's solutions will work, but if somebody tries to type your URL without the "www", they won't see your site. Changing Apache settings can be daunting, but you could follow Bitfreeze's "change your web server settings" directions and make the empty index.html file an index.php file that redirects to the "www" version of your site.

If your server allows local htaccess files and supports mod_rewrite, you could use a third option which will work nicely...upload a text file named ".htaccess" to your web root with the code below (change "mywebsite.com" to your domain). This will force everybody to see your site as "www.mywebsite.com".
RewriteEngine on

## enforce "www"
RewriteCond %{HTTP_HOST}   !^www.mywebsite.com.*$ [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteRule ^.*$           http://www.mywebsite.com%{REQUEST_URI} [L,R=301]

Open in new window

0
Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

 
LVL 108

Expert Comment

by:Ray Paseur
ID: 33466380
Why is this a problem?  Why not just ignore it, until you have a web site design that differentiates between (for example) www.example.com and test.example.com?

I would not worry about it at all, but if you care, you can ask your hosting company to fix it for you.  Refer them to this thread in EE.

Cheers, ~Ray
0
 
LVL 2

Expert Comment

by:Tiller79188231
ID: 33466973
BitFreeze is right, there is no reason to do a rewrite rule when this should be handled by the dns server
0
 
LVL 6

Expert Comment

by:merwetta1
ID: 33469821
I don't think it can be handled by DNS, because ideally these URLs should work:
http://mywebsite.com
http://www.mywebsite.com

But these (and all other subdomains) should not:
http://abc.mywebsite.com
http://xyz.mywebsite.com

Tiller79188231...how can you do that with DNS?
0
 

Author Closing Comment

by:Dido123
ID: 33470490
Yes, it was due to a wild card in my DNS settings which I removed it and now everything like I want it.

Thank you all for your time.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now