• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 219
  • Last Modified:

htaccess restrict subdomain

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?
  • 2
1 Solution
Ray PaseurCommented:
I don't think this is a PHP question.  Might want to ask a moderator to remove that topic area.
You can use this:
RewriteEngine On
<Files "index.php">
    Order deny,allow
    Deny from all
    Allow from

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.
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.
Ray PaseurCommented:
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

Featured Post

Evaluating UTMs? Here's what you need to know!

Evaluating a UTM appliance and vendor can prove to be an overwhelming exercise.  How can you make sure that you're getting the security that your organization needs without breaking the bank? Check out our UTM Buyer's Guide for more information on what you should be looking for!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now