Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

htaccess rewrite rules with mod_GeoIP

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!

like image 526
coloradohiker Avatar asked Feb 02 '12 16:02

coloradohiker


People also ask

How to use mod_rewrite in htaccess?

Begin mod_rewrite in .htaccess Loop Stopping Code Cache-Friendly File Names SEO friendly link for non-flash browsers Removing the Query_String Requiring a subdomain like www Sending requests to a php script Setting the language variable based on Client Only allowing certain request_methods Begin mod_rewrite in .htaccess

How to enable http override in XAMPP?

To finish up, open the http.conf file (the default settings for XAMPP, that get overwritten with you .htaccess file rules on a directory basis), located by default at C:\xampp\apache\conf\http.conf. Find all occurances of AllowOverride None and change it to AllowOverride All. After restarting XAMPP everythign should work.

Is there a cheat sheet for Apache htaccess?

.htaccess Cheat Sheet All the important Apache .htaccess web server rules and config options Welcome to our fast loading one page .htaccess cheat sheet with all major .htaccess rules listed. We have no ads, no javascript. Just plain HTML (and a .css file), so it should load super fast.

What does the allowoverride directive do in htaccess?

In a nutshell changing the AllowOverride directive in the http.conf file decalres which directives in .htaccess files can override directives from httpd.conf, this is discussed in more dept over here, but basically by having this directive set to None, you’re stopping individual htaccess files from working locally.


1 Answers

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.

like image 107
zekus Avatar answered Oct 09 '22 00:10

zekus