i try to do the following.
- denied directly access to example.domain.com
- allow access from to example.domain.com from another.domain.com
- 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?
CodePudding user response:
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]
CodePudding user response:
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]