Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8917489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:29:41+00:00 2026-06-15T05:29:41+00:00

Using .htaccess I am successfully redirecting a specific set of subfolders ( blog ,

  • 0

Using .htaccess I am successfully redirecting a specific set of subfolders ( blog, dev, media, etc ) to subdomains.

Like so:

www.website.com/_subs/dev/foo gets directed to dev.website.com/foo

This has been achieved with the following fragments of code:

RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} ^website.com$
RewriteRule ^(.*)$ http://www.website.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} website.com
RewriteCond %{REQUEST_URI} ^/_subs/blog/(.*)$
RewriteRule .* http://blog.website.com/%1 [R=301,L]

RewriteCond %{HTTP_HOST} website.com
RewriteCond %{REQUEST_URI} ^/_subs/dev/(.*)$
RewriteRule .* http://dev.website.com/%1 [R=301,L]

RewriteCond %{HTTP_HOST} website.com
RewriteCond %{REQUEST_URI} ^/_subs/media/(.*)$
RewriteRule .* http://media.website.com/%1 [R=301,L]

The question is:

How do I prevent access to the /_subs folder if a request ISN’T made to one of my specific subfolders?

I would like any requests being made to www.website.com/_subs/foo to simply be redirected to www.website.com

I have tried using a 301 redirect along with various other attempts to no avail 🙁

Any help would be greatly appreciated.

Cheers

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T05:29:43+00:00Added an answer on June 15, 2026 at 5:29 am

    Your rules are a lot more complicated than they need to be and I think that’s making the solution harder to see.

    Here’s what I came up with:

    RewriteEngine on
    RewriteBase /
    
    RewriteCond %{HTTP_HOST} ^(www.)?website.com$
    RewriteRule ^_sub/(blog|dev|media)/?(.*)$ http://$1.website.com/$2 [R=301,L]
    
    RewriteCond %{HTTP_HOST} ^(www.)?website.com$
    RewriteRule ^_sub(/.*)$ - [F]
    
    RewriteCond %{HTTP_HOST} ^website.com$
    RewriteRule ^(.*)$ http://www.website.com/$1 [R=301]
    

    The RewriteConds limit the first two rules so that they only run on website.com and www.website.com. Presumably you might have a url like http://blog.website.com/_sub/this-rocks in the future that you don’t want redirected.

    Including both domains in the first rewrite means you will have one less 301 redirect, which should make a request to http://website.com/_sub/blog redirect directly to http://blog.website.com much faster. The L makes sure that nothing that matches this rule will get marked as forbidden.

    The second rewrite returns 403 for anything starting with /_sub that is not matched by the first rule. The / is inside the group so that this will match /_sub, /_sub/, and /_sub/.*. If the / were outside you would not be able to 403 /_sub without a separate rule.

    The last rewrite is the same as your very first rule – there is no need to put the L, though, as it’s already the last rule to process.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using htaccess to redirect non-www to www like this: user typea: mydomain.com
I have successfully set up localisation on my website using php gettext, and a
I'm trying to implement a solution using .htaccess and wildcard subdomains so that http://subdomain.example.com
I'm working on an aircraft website and using a .htaccess file to rewrite the
Using .htaccess, I need to redirect all requests from http://www.domain, http://domain, https://domain to; https://www.domain.com
Using .htaccess, how can I get my website to be able to do this.
Im using .htaccess to turn my url from www.mysite.com/profile.php?name=name to www.mysite.com/name/name But I've struck
I am using htaccess. I try to pass a value in url like 'C++'.
I have a website built using Django on Dreamhost deployed successfully with Passenger and
I'm using http://github.com/lakshmivyas/hyde to generate my website, and it included .htaccess mod_rewrite rules, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.