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 8095785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:14:59+00:00 2026-06-05T21:14:59+00:00

I have looked around on Google and StackOverflow for the answer to this question,

  • 0

I have looked around on Google and StackOverflow for the answer to this question, but the fact that I don’t know much about .htaccess doesn’t help me decide what the correct answers for my situation are, so I am asking here.

My situation is that I have several sites that are using the same physical directory as their root on the server.

This is all working fine but I wanted to make sure that each site can’t access each others images etc from the browser unless they are on the correct domain.

Currently I have a file structure like this:

/resources/{resource}/{full_domain_name}

So for example www.domain.co.uk would have a structure like this:

http://www.domain.co.uk/resources/images/www.domain.co.uk/some_image.jpg

But if www.domain_2.co.uk exists using the same physical directory for the site root then they can look at other domain’s resources from their own domain, like this:

http://www.domain_2.co.uk/resources/images/www.domain.co.uk/some_image.jpg

This isn’t really a major problem since there is absolutely no sensitive information stored in these directories, but it’s more of an annoyance and I would rather users were not able to do it (not that anyone actually has so far).

I tried putting a .htaccess file into the /resources directory but I’m stuck with the regular expressions etc.

I basically want to make sure that the URI contains the current domain name otherwise redirect to a 403 error page.

This is what I came up with:

RewriteCond %{REQUEST_URI} !^(/resources/[^/]*/%{HTTP_HOST})(.*)$
RewriteRule ^(.*)$ /error/403.php

The reason I put in the [^/] bit is because there are several folders, for example:

/resources/images/{full_domain_name}
/resources/scripts/{full_domain_name}
/resources/stylesheets/{full_domain_name}

Could anybody help me with these conditions?

Any help would be appreciated.

  • 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-05T21:15:01+00:00Added an answer on June 5, 2026 at 9:15 pm

    This is terrific question and if I could I would have upvoted 10+ times. I am posting my answer even though you have an accepted answer here as I really had to dig through all my Apache resources to come up with the answer. Here is the rule you will need for this problem:

    Options +FollowSymLinks -MultiViews
    # Turn mod_rewrite on
    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{HTTP_HOST}:%{REQUEST_URI} !^([^:]+):/resources/[^/]+/\1/.+ [NC]
    RewriteRule ^resources/[^/]+/[^/]+/.+ - [F,NC,NE]
    

    PS: Since we cannot use % variables on RHS as back-reference, I am using special regex back-reference variable \1 in the RewriteCond here.

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

Sidebar

Related Questions

I looked around but haven't found an answer to this. I have a CentOS
I have looked around here and the Internet in general but it seems this
Sorry if this is obvious but have looked around and can't get this working:
I've looked around (here at stackoverflow and with Google) but I can't seem to
I've got zero experience with Python. I have looked around some tutorial materials, but
I've looked around and have bits and pieces but can't put the puzzle together.
I've looked around but have yet to find a great solution the the following
I've looked around on stack overflow for days and have not seen an answer
I know that this sounds trivial, but I did not realize that the sort()
I looked around and I may have confused google with the keywords. I am

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.