php - .htaccess apache URL rewriting -


i have performed multiple searches , have yet find looking for.

i need perform url rewrites don't have expertise , knowledge code rewrites. have begun learning regex , apache url rewriting.

onto problem. website use these re-directs on .com domain users coming multiple countries. on website there online shop. on initial landing page able select country , take

www.domain.com/*country*/ 

which has online shop.

now gets complicated. depending on country user clicked, append countries name url after have clicked on product , entered shop.

e.g "www.domain.com/*country*/*product-category*/ 

at moment, when click on product after selecting country goes

www.domain.com/*product-category*/ 

the site running wordpress. not sure other information required.

thanks guys!

if have control on implementation of online shop implementation solution might quite easy: said somehow have make sure urls sent out shop, urls 1 can click/select inside shop navigation, carry chosen country coding within. since shop called information in first place information available , easy usable way describe structure of base url: www.domain.com/*country*/. easy use since country code part of base url of shop, not arbitrary argument has handled in explicit manner. have take care of this: make shop use relative links in urls sends out client. relative links relative paths (so path without leading slash(/)). browsers handle relative links prepending base url of current page loaded create full url. in situation means:

  • base url: www.domain.com/*country*/
  • relative link: product/123456/action/buy (just example)
  • url composed browser: www.domain.com/*country*/product/123456/action/buy

this want: not have handle/specify country code in explicit manner, yet contained in urls. "just" have make sure consequently use relative links in shop implementation.

a side note: in general 1 should prefer relative links absolute links or urls, since keeps implementations flexible, relocatable , portable. references external targets should coded urls.

other approaches might these:

  • using "landing page" request relay online shop routing requests. means enter scripting level in routing/rewriting process, have more means @ hand. in specific use php sessions @ routing level.
  • changing structure of base url: using virtual hosts instead of urls path code chosen country, domain names mozambique.domain.com or spitzbergen.domain.com. domain name automatically taken account existing implementation, although virtual hosts share same single installation.
  • considering "referrer url" of each incoming request during rewriting process. easy implement, afraid not safe browsers, since relies on http referrer header present in all requests, can blocked easily. in case deep urls lead error, since required information missing.
  • changing target of urls on-the-fly means of javascript. has advantage not have change in shops implementation, except of referencing single script file in header. script contains code changes target url of scripts or form submissions initiated user. again, in previous approach, not appear robust, since requires use of javascript may disabled on client side. on other hand not mean insecure (being secure , being robust 2 different things), since missing country code not hold risk, leads error has handled.

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -