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).
Related
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
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>
I'm trying to deny all requests sent to a website, but allow only 2 IP-addresses.
I've learned this should be done with .htaccess.
Basically there are 3 modules: Website Server, Form-handling Server and my own network IP.
Let's appoint the following IP addresses to the servers:
Website Server: 1.1.1.1
Form-handling Server: 2.2.2.2
Own Network: 3.3.3.3
The .htaccess is placed in the public_html directory of the form-handling server (2.2.2.2).
Now, this works:
order deny,allow
deny from all
allow from 3.3.3.3
The form-handling server is accessible with my own browser, but the form post request sent from the website is blocked. (which is good, in this case)
But when I edit the .htaccess to the following, the form post request is still blocked:
order deny,allow
deny from all
allow from 1.1.1.1
allow from 3.3.3.3
To make sure this .htaccess is functional I tried:
order deny,allow
deny from all
allow from 1.1.1.1
Now I cannot reach the Form-handling Server. Which proves the .htaccess is 'running'. (also, the Website Server cannot access the server tho..)
How can I achieve that the Website server has access to the Form-handling Server (and preferably me as well), but any other visitor/server hasn't?
Worth knowing: When I delete these lines from my .htaccess, the connection between the Website and Form-handling server works beautifully.
I am pretty sure your htaccess is ok. Most likely your webserver connects the form server with a different ip - i.e. the IP from the internal LAN between your webserver and your form server is different.
I have a magento multi store hosting. There hosted around 6 websites. Now I need to create another store using my sub domain. I created website, store and store view in magento back end and edited htaccess file. suppose my sub domain is abc.domain.in, this is my htaccess code,
SetEnvIf Host www\.abc\.domain\.in MAGE_RUN_CODE=abc_domain_in
SetEnvIf Host www\.abc\.domain\.in MAGE_RUN_TYPE=website
SetEnvIf Host ^abc\.domain\.in MAGE_RUN_CODE=abc_domain_in
SetEnvIf Host ^abc\.domain\.in MAGE_RUN_TYPE=website
And I changed base url for secured and unsecured in system --> configuration. But if I go to my website it shows 403 forbidden. It says
Forbidden
You don't have permission to access / on this server. Additionally, a
500 Internal Server Error error was encountered while trying to use an
ErrorDocument to handle the request.
Why is it so?? Any body can help me?
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).