Solved

htaccess restrict subdomain

Posted on 2016-08-19
4
70 Views
Last Modified: 2016-08-24
I have a subdomain that I want to restrict access to accept my IP address.  Is there a way to setup my htaccess file to redirect anyone to my main domain if my subdomain is address is entered?  Only my IP?
0
Comment
Question by:rgranlund
  • 2
4 Comments
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 41763232
I don't think this is a PHP question.  Might want to ask a moderator to remove that topic area.
0
 
LVL 2

Accepted Solution

by:
Marcos_Cardoso earned 500 total points
ID: 41763987
You can use this:
RewriteEngine On
<Files "index.php">
    Order deny,allow
    Deny from all
    Allow from 196.227.47.17
</Files>

ErrorDocument 403 http://www.maindomain.com

Open in new window


It will restrict the access for all but one IP address. And will redirect all denials to the main domain.
0
 
LVL 76

Expert Comment

by:arnold
ID: 41764030
There are additional ways but  you need to provide more details on what you want.

you have www.mydomain.com you want to limit access to somesubdomain.mydomain.com or is it www.mydoain.com/somefolder?

if your subdomain uses PHP, you can add the redirect login into the PHP.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 41764253
Even though this is not really a PHP question, there are some design patterns that have emerged in the top levels of the community.  Knowing these patterns may be useful for your work.  They will work with RESTful request routing.  In the context of these examples, the s? has the same meaning as the regular expression: The s is an optional character.
https?://domain.com       -->  https://domain.com
https?://www.domain.com   -->  https://domain.com
https?://test.domain.com  -->  https://test.domain.com
https?://dev.domain.com   -->  https://dev.domain.com
https?://help.domain.com  -->  https://help.domain.com

https?://{{anything-else}}.domain.com  -->  https://domain.com/404

Open in new window

The effect of this scheme is
(1) ensure that everything is handled over HTTPS,
(2) preserve true subdomain routing for meaningful subdomains test, dev, and help,
(3) make www subdomain have the same meaning as no subdomain (it usually is),
(4) give a valid 404 response for other unknown URLs
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

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

18 Experts available now in Live!

Get 1:1 Help Now