skip to Main Content

I am trying to do the following.

  1. denied directly access to example.domain.com
  2. allow access from to example.domain.com from another.domain.com
  3. allow to load resource files (css, js) when the the user comes form another.domain.com to example.domain.com

Points 1 and 2 i solved like this:
RewriteCond %{HTTP_REFERER} !http(s)?://(www.)?another.domain.com/$ [NC] RewriteRule ^.*$ - [F]

But i can not to load resource files. I get the error message 403.
I tried with this code, but it’s not working.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond $1 ^(index.html|robots.txt)
RewriteRule ^.*$ ^.*$ [L]
RewriteCond %{HTTP_REFERER} !http(s)?://(www.)?another.domain.com/$ [NC]
RewriteRule ^.*$ - [F]

I am a quite new with htaccess, can someone help me to solve this problem?

2

Answers


  1. Chosen as BEST ANSWER

    i have found a solution for me:

    RewriteCond %{REQUEST_FILENAME} ^.+(.js|.css|.json|.jpg|.png|.woff2|.woff|.ttf)$
    RewriteRule ^.*$ - [L]
    RewriteCond %{HTTP_REFERER} !http(s)?://(www.)?another.domain.com/$ [NC
    RewriteRule ^.*$ - [F]
    

  2. With your shown samples, please try following .htaccess rules file. Make sure to clear your browser cache before testing your URLs.

    RewriteEngine ON
    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteCond %{HTTP_HOST} ^(www.)?example.domain.com$ [NC]
    RewriteRule ^ - [F,L]
    
    RewriteCond %{HTTP_HOST} ^(www.)?another.domain.com$ [NC]
    RewriteRule ^(.*)/?$ http://example.domain.com/%1 [R=301,L]
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} (?:index.html|robots.txt)/?$ [NC]
    RewriteRule ^ - [F,L]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search