Forum Moderators: phranque
The site is multilingual (currently only EN/FR) and almost every page has the option of navigating directly to it or via language code... ie. /page or /en/page. Right now I have it so every rule is looked at a second time for language.
After numerous structure checks, the last item is a 'city' catch all - so that if no other rules have matched it will take anything and pass to a php page which checks if it is a city (so you can do /newyork /denver etc) - the citis need to be scalable.
A.
is there a better way of checking for languages with each rule - I assume i don't need to duplicate every rule to check for EN¦FR
B.
what is more efficient for checking if a city exists?
- should I use htaccess and just have a huge list of possible cities: ie (newyork¦dever¦etc¦etc¦etc¦etc)
- or should I keep as is which requires every request not matcing a rule in the htaccess to check mysql and see it it is a city?
- should I be using mapping?
thanks in advance!
my sample...
Options +FollowSymLinks
RewriteEngine on
#
#generic
#
RewriteRule ^admin/?.*$ - [PT]
RewriteRule\.(gif¦png¦jpe?g¦swf)$ - [L]
RewriteRule ^home/?$ index.php [L]
RewriteRule ^(en¦fr)/?$ index.php?lang=$1 [L]
RewriteRule ^(en¦fr)/home/?$ index.php?lang=$1 [L]
#
#goods & b2b
#
RewriteRule ^(products¦b2b)/?$ $1/index.php [L]
RewriteRule ^(en¦fr)/(products¦b2b)/?$ $1/index.php?lang=$2 [L]
#
RewriteRule ^(products¦b2b)/(mens¦womens¦accessories)/?$ $1/products.php?gender=$2 [L]
RewriteRule ^(en¦fr)/(products¦b2b)/(mens¦womens¦accessories)/?$ $1/products.php?lang=$2&gender=$3 [L]
#
RewriteRule ^(products¦b2b)/(mens¦womens¦accessories)/([^/]+)/?$ $1/products.php?gender=$2&parent=$3 [L]
RewriteRule ^(en¦fr)/(products¦b2b)/(mens¦womens¦accessories)/([^/]+)/?$ $1/products.php?lang=$2&gender=$3&parent=$4 [L]
#
RewriteRule ^(products¦b2b)/(mens¦womens¦accessories)/([^/]+)/([^/]+)/?$ $1/products.php?gender=$2&parent=$3&cat=$4 [L]
RewriteRule ^(en¦fr)/(products¦b2b)/(mens¦womens¦accessories)/([^/]+)/([^/]+)/?$ $1/products.php?lang=$2&gender=$4&parent=$5&cat=$6 [L]
#
RewriteRule ^(products¦b2b)/([^/]+)/?$ $1/$2.php [L]
RewriteRule ^(en¦fr)/(products¦b2b)/([^/]+)/?$ $1/$3.php?lang=$2 [L]
#
RewriteRule ^(products¦b2b)/([^/]+)/([^/]+)/?$ $1/$2_$3.php [L]
RewriteRule ^(en¦fr)/(products¦b2b)/([^/]+)/([^/]+)/?$ $1/$3_$4.php?lang=$2 [L]
#
#about
#------------------------------------------------------------------------------
#
RewriteRule ^about/media/([0-9]+)/?$ about/media.php?aid=$1 [L]
RewriteRule ^(en¦fr)/about/media/([0-9]+)/?$ about/media.php?lang=$1&aid=$2 [L]
#
RewriteRule ^about/([^/]+)/([^/]+)/?$ about/$1_$2.php [L]
RewriteRule ^(en¦fr)/about/([^/]+)/([^/]+)/?$ about/$2_$3.php?lang=$1 [L]
#
cities catch all
#------------------------------------------------------------------------------
#
RewriteRule ^([^/]+)/?$ stores/city.php?city=$1 [L]
RewriteRule ^(en¦fr)/([^/]+)/?$ stores/city.php?lang=$1&city=$2 [L]
#
RewriteRule ^([^/]+)/([^/]+)/?$ stores/info.php?city=$1&store=$2 [L]
RewriteRule ^(en¦fr)/([^/]+)/([^/]+)/?$ stores/info.php?lang=$1&city=$2&store=$3 [L]
#
#errors
#------------------------------------------------------------------------------
RewriteRule ^404/?$ 404.php [L]
RewriteRule ^(en¦fr)/404/?$ 404.php?lang=$1 [L]
#
ErrorDocument 404 /404.php
The easier way of keeping track of language (instead of "(en¦fr)") might be using mod_rewrite's environment variable facility. If you affix a line with something like [E=lang:fr] you can just refer to the lang variable in later RewriteRules. I've never used this, but it's detailed in the Apache docs.