14

I'm having some issues with mod_geoip for an ecommerce site that has 3 different stores. We have our main store at root/store, but also have have stores at root/ukstore and root/austore. The main root/store contains a /skin, /media, and /js directories that contain all css, images, and javascripts. With this current setup, the urls flawlessly swap out the base, but leaves the rest of the URL intact so if a user from the UK goes to root/store/category/product/ they get redirected to root/ukstore/category/product/.

2 things that are issues now.

Whenever a customer accesses a secure page like checkout or account, the URLs for css and javascript are being rewritten to root/ukstore/skin or root/ukstore/js. Is there something I'm missing in regards to SSL for those URLs?

Secondly, if a user from South Africa accesses the store, they are rewritten to the UK store and all the css, js, images are perfectly linked back to store/skin, but if a user from the United Kingdom accesses the store then the URLs for css, js, and images are trying to be rewritten to root/ukstore/skin

Here is the code in my htaccess file in root/store. Each store also has their own htaccess file, but without much in there.

<IfModule mod_geoip.c>
GeoIPEnable On

Options +FollowSymLinks
RewriteEngine on
#skip processing directories
RewriteRule ^store/skin/  - [L,NC]
RewriteRule ^store/media/  - [L,NC]
RewriteRule ^store/js/  - [L,NC]

RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^(AQ|AU|MY|BV|BN|BN|MM|KH|CN|CX|CC|CK|GQ|FJ|PF|GU|GW|HM|HK|ID|KI|KR|KP|KR|LA|MO|MY|MH|FM|MM|NR|NC|PG|NZ|NU|NF|PG|CN|PH|PN|WS|SG|SB|KR|LK|BN|TW|TW|AU|TH|TL|TK|TO|TV|VU|VN|VN|WF)$
RewriteCond %{REQUEST_URI} ^/store(/.*)$ [NC]
RewriteRule ^ /austore%1 [L,R]

#UK Store Rewrites
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^(AF|AX|AL|DZ|AD|AO|AM|AT|AZ|BH|BD|IS|BY|BE|BJ|BT|BA|BW|IO|BG|BF|BI|GB|CM|ES|CV|CF|TD|GB|KM|CG|CD|CG|CD|CI|HR|CY|CZ|CZ|BJ|DK|DJ|EG|ER|EE|ET|FO|FI|FR|TF|GA|GM|GE|DE|GH|GI|GD|GR|GL|GN|VA|HU|IS|IN|IR|IR|IQ|IE|IL|IT|CI|JO|KZ|KE|KW|KG|LV|LB|LS|LR|LY|LY|LI|LT|LU|MK|MG|MW|MV|ML|MT|MR|MU|MC|MC|MN|ME|MA|MZ|NA|NP|NL|NE|NG|IE|NO|OM|PK|PS|PS|CG|PL|PT|QA|CI|MK|ZA|CD|RE|RO|RU|RW|SH|SM|ST|SA|SN|RS|SC|SL|SK|SI|SO|SO|ZA|ES|SD|SJ|SZ|SE|CH|SY|SY|TJ|TZ|TN|TR|TM|AE|UG|UA|AE|GB|BF|UZ|VA|GB|EH|YE|ZM|ZW)$
RewriteCond %{REQUEST_URI} ^/store(/.*)$ [NC]
RewriteRule ^ /ukstore%1 [L,R]
</IfModule>

Any help would be greatly appreciated!

Leigh
  • 12,859
  • 3
  • 39
  • 60
coloradohiker
  • 221
  • 3
  • 11
  • Do your css/image urls start with a leading slash i.e. `/store/skin/my.css` or are they `skin/my.css`? – Ulrich Palha Feb 02 '12 at 17:04
  • It's a magento setup, so they are actually /store/skin/frontend/default/theme/css/my.css. But within the CSS they are url(../images/bg-main3.jpg) – coloradohiker Feb 02 '12 at 17:22
  • Given the CSS has a leading slash, the first rule will prevent it being rewritten. When you said `trying to be rewritten to root/ukstore/skin` are you seeing redirects to `/ukstore/skin` or is it that way in the .html for the Ukstore? – Ulrich Palha Feb 02 '12 at 17:49
  • It's actually being rewritten to /ukstore/skin/etc.. which is then giving a 404. – coloradohiker Feb 02 '12 at 17:54
  • 3
    Per rules, the rewrite should not happen. If you can replicate this in a dev environment, I suggest turning on the RewriteLog and LogLevel to see what is happening i.e. `RewriteLog "/path-to-logs/logs/rewrite.log"` and `RewriteLogLevel 9 ` in your virtual host. – Ulrich Palha Feb 02 '12 at 18:10
  • I was able to fix this issue up by using this line of code: RewriteRule ^(skin|js) - [L,NC] instead of the processing rules listed above. Do you wee any issues with this config? – coloradohiker Feb 09 '12 at 15:09
  • You should answer your own question and accept it, since it still show up as unanswered, while the problem seem to be solved. :) – Qben Oct 14 '13 at 07:30

2 Answers2

1

The problem is that you are using the rewrite conditions in a .htaccess context so the conditions should be relative to the directory you are in and that is the reason why the rewrite conditions relative to the skin, js and media mentioned in the question do not match. You should replace them with something like:

RewriteRule ^(skin|media|js)/ - [L,NC]

or, as mentioned in the mod_rewrite guide ( http://httpd.apache.org/docs/current/mod/mod_rewrite.html#RewriteRule )

If you wish to match against the full URL-path in a per-directory (htaccess) RewriteRule, use the %{REQUEST_URI} variable in a RewriteCond.

zekus
  • 848
  • 8
  • 16
0

Ip-based redirection could fail and what usually people want is language-based redirection. You can read the language configured in the user browser and just redirect them to a language that your web has. Just like that:

RewriteCond %{HTTP:Accept-Language} ^(en|ja|de|zh|fr|it|nl|fi|sv|no) [NC]
RewriteRule ^$ /en [R=303,L,QSA]

And what you want in your approach is to have a direct access to the static files in your server, this can be achieved setting this condition, so static files don't get rewrited

RewriteCond %{REQUEST_FILENAME} !-f
David Lemon
  • 1,560
  • 10
  • 21