Solved

Any subdomain works!!

Posted on 2010-08-17
7
360 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

914 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

19 Experts available now in Live!

Get 1:1 Help Now