.htaccess: SetEnvIf Host doesn't work for subdomain - .htaccess

I have to set different Env for different subdomains. For example, domain/subdomain1 MAGE_RUN_CODE=mobile_en, but domain/subdomain2 MAGE_RUN_CODE=global
This code works:
SetEnvIf Host .*mydomain.net.* MAGE_RUN_CODE=mobile_en
But this code doesn't work
SetEnvIf Host .*mydomain.net/ahava-m1-mobile.* MAGE_RUN_CODE=mobile_en
How should I change second code to make it working?

As explained in the comments above, HOST keyword is used for http host headers ie example.com . Since your url contains a path segment /ahava-m1-mobile you need to match against Request-uri variable.
SetEnvIF request_uri ^/ahava-m1-mobile MAGE_RUN_CODE=mobile_en

Related

need to add basic auth for uri backend but need to exlude some of the uri

I need to add basic auth for uri backend but need to exlude some of the uri, i have try to add SetEnvIf
SetEnvIf REQUEST_URI "(login|admin)" PROTECTED
SetEnvIf REQUEST_URI "^/api/*" !PROTECTED
The idea is protect uri that containt login or admin but allow admin/api/*
but it's doesn't work, can you guys give me some hint.
Your regex is problematic here:
`^/api/*`
Will match /api at the start and * is useless after /.
You can do this in single SetEnvIf rule by using negative lookahead:
SetEnvIf REQUEST_URI "(login|admin(?!/api/))" PROTECTED
(?!/api/) means skip /admin/api/ from this rule

Apache Access Control to IPs (X-Forwarded-For) or valid-user

I used to block access to certain folder of my Apache server using valid-user or ip directive, like the following:
<Directory "/home/domain/public_html/secure">
Require ip x.x.x.x
Require ip y.y.y.y
AuthType Basic
AuthUserFile "/home/domain/secure/pass"
AuthName "Authentication Required"
Require valid-user
Satisfy Any
</Directory>
Now, I have placed my server behind an F5-BIGIP device which won't let me fully DNAT client's connections. The device is also behind a Linux server that serves as gateway with DNAT/SNAT rules hat are working accordingly. I can log client's IPs through X-Forwarded_For, though. But my Apache directives are not working anymore.
So my question is, is there any way I could use something like Require X-Forwarded-For x.x.x.x?
My Apache Version is:
[root#webserver1 ~]# apachectl -version
Server version: Apache/2.4.6 (CentOS)
Server built: May 12 2016 1
0:27:23
Thanks in advance.
You should be able to do something like:
SetEnvIf X-Forwarded-For x.x.x.x$ foo
SetEnvIf X-Forwarded-For y.y.y.y$ bar
...
Require env foo
Require env bar
You can't access headers as part of the require directive directly, so instead set an environment variable that matches, and use this as the test:
SetEnvIf X-Forwarded-For "^123\.456\.78\.9" MyAllowedIPAddress
Require env MyAllowedIPAddress
Notes:
SetEnvIf expects a Regular Expression as the test
The environment variable name can be whatever you want (that doesn't clash!)
SetEnvIf is evaluated after <if> directives, so will be confusing if you use both. An alternative using <if> is below.
<if "%{HTTP:X-Forwarded-For} == '123.456.78.9'">
Require all granted
</if>
<else>
Require all denied
</else>

Block certain IPs using .htaccess behind Cloudflare

I use Cloudflare for my site so usual .htaccess rule won't work. I need to block certain IPs to access my website.
I found this one but won't work:
SetEnvIf X-FORWARDED-FOR 1.1.1.1 deny
order allow,deny
allow from all
deny from env=deny
I also tried this with the same result..
RewriteEngine On
SetEnvIf X-FORWARDED-FOR 109.100.238.188 deniedip
order allow,deny
deny from env=deniedip
"I use Cloudflare for my site so usual .htaccess rule won't work."
These rules should still work fine as long as you have something set to restore visitor IP back to your logs/server (CloudFlare IPs will show without a mod, which could throw things off a little bit).

Restricting access from only 3 domains in my htaccess fle - SetEnvIf Referer

Hi so i have the below working:
SetEnvIf Referer "^http://sub\.site1\.com/yvvl/Portal/" local_referral
SetEnvIf Referer "^http://sub\.site2\.com/yvvl/Portal/" auth_referral
SetEnvIf Referer "^http://sub\.site3\.com/yvvl/Portal/" authC_referral
Order Deny,Allow
Deny from all
Allow from env=local_referral
Allow from env=auth_referral
Allow from env=authC_referral
what i dont know how to do is wildcard it so anything from those 3 domains will be accepted my preg is not good at all
Thanks
Just remove everything after the .com:
SetEnvIf Referer "^http://sub\.site1\.com/" local_referral
SetEnvIf Referer "^http://sub\.site2\.com/" auth_referral
SetEnvIf Referer "^http://sub\.site3\.com/" authC_referral
Since there's no fence-post for the end of the referer (indicated by the $ character) that will match anything that starts with http://sub.site1.com/ etc.

Magento Domain Configuration

I am following an example in a Magento book which
calls for the following to be written inside the .htaccess file:
SetEnvIf Host www\.acmefurniture.com MAGE_RUN_CODE=furniture_en
SetEnvIf Host www\.acmefurniture.com MAGE_RUN_TYPE=store
SetEnvIf Host ^acmefurniture.com MAGE_RUN_CODE=furniture_en
SetEnvIf Host ^acmefurniture.com MAGE_RUN_TYPE =store
SetEnvIf Host www\.acmeelectronics.com MAGE_RUN_CODE=electronics_en
SetEnvIf Host www\.acmeelectronics.com MAGE_RUN_TYPE=store
SetEnvIf Host ^acmeelectronics.com MAGE_RUN_CODE=electronics_en
SetEnvIf Host ^acmeelectronics.com MAGE_RUN_TYPE =store
SetEnvIf Host www\.acmeoutdoor.com MAGE_RUN_CODE=outdoor_products
SetEnvIf Host www\.acmeoutdoor.com MAGE_RUN_TYPE=website
SetEnvIf Host ^acmeoutdoor.com MAGE_RUN_CODE=outdoor_products
SetEnvIf Host ^acmeoutdoor.com MAGE_RUN_TYPE=website
I would like to use such an example except that I am running an xampp
server on a Windows 7 machine behind a firewal and do not own several
domain names.
So what I would like to ask, what can I use in place of acmefurniture,
acmeelectronics, and acmeoutdoor on a localhost server (where I am only
beginning to test magento)?
Of course, once out on the web a similar example would require the web
store maintainers to purchase their own domains etc... but for now I
was just wondering what to do to see how the pages in the example
show up on localhost.
I have tried modifying my C:\Windows\System32\drivers\etc\hosts file
and adding the following lines:
and then writing the following inside my C:\xampp\htdocs\magento.htaccess file:
SetEnvIf Host en.furniture.localhost MAGE_RUN_CODE=furniture_en
SetEnvIf Host en.furniture.localhost MAGE_RUN_TYPE=store
SetEnvIf Host en.electronics.localhost MAGE_RUN_CODE=electronics_en
SetEnvIf Host en.electronics.localhost MAGE_RUN_TYPE=store
SetEnvIf Host products.localhost MAGE_RUN_CODE=outdoor_products
SetEnvIf Host products.localhost MAGE_RUN_TYPE=website
but with this change when I point my browser to
http://en.furniture.localhost/magento
or
http://products.localhost/magento
I still get the same result. I was supposed to get two different pages.
Anyone have any idea why I am getting the same page in both cases?
How can I configure my Windows 7 + XAMPP + Magento environment so as to
get different sites in both cases?
Thanks,
John Goche
You can use any domain on your localhost. Even google.com. Just specify it in you hosts file. See more info here http://helpdeskgeek.com/windows-7/windows-7-hosts-file/
When you type in any domain name into your browser's address bar it first looks into the local hosts file. If the record is found there browser will send a request to a specified server which in your case is 127.0.0.0.
You could modify your windows host file to trick windows in to thinking those domain names point to your local machine:
for example, you would add:
127.0.0.1 somedomain.com
127.0.0.1 anotherdomain.com
When you type those into your web browser windows will try and look at your local WAMP setup for the domains.
You would then change your .htaccess like so:
SetEnvIf Host somedomain.com MAGE_RUN_CODE=[store1]
SetEnvIf Host somedomain.com MAGE_RUN_TYPE=store
SetEnvIf Host anotherdomain.com MAGE_RUN_CODE=[store2]
SetEnvIf Host anotherdomain.com MAGE_RUN_TYPE=store
where you would replace [store1] and [store2] with the store code for each store view which you can get from the magento admin (store management).

Resources