Reputation: 626
I have a problem with my mod_rewrite rules that I cannot manage to figure out myself!
Essentially I have a directory of countries (100+) that will display (#worldwide) the country information depending on the URL.
I also have a fishing clubs directory that I have instructed .htaccess to ignore this rule. This seems to be working ok for the base directory, however I cannot get it to redirect /fishing-clubs/name-of-country to /fishing-clubs/index.php?country=COUNTRY
website.com//fishing-clubs/ is going to the /fishing-clubs/ directory.
However website.com/fishing-clubs/name-of-country/ is giving a 404 error.
Any idea what is wrong with my code?
RewriteRule ^fishing-clubs/ - [L,NC]
RewriteRule ^fishing-clubs/([A-Za-z0-9-\s_()]+)/?$ /fishing-clubs/index.php?country=$1 [NC]
#worldwide
RewriteRule ^([A-Za-z0-9-\s_()]+)/?$ country-admin-city.php?country=$1 [NC]
RewriteRule ^([A-Za-z0-9-\s_()]+)/([A-Za-z0-9-\s_()]+)/?$ country-admin-city.php?country=$1&admin1code=$2 [NC]
RewriteRule ^([A-Za-z0-9-\s_()]+)/([A-Za-z0-9-\s_()]+)/([A-Za-z0-9-s_()]+)/?$ country-admin-city.php?country=$1&admin1code=$2&admin2code=$3 [NC]
RewriteRule ^([A-Za-z0-9-\s_()]+)/([A-Za-z0-9-\s_()]+)/([A-Za-z0-9-s_()]+)/([A-Za-z0-9-s_()]+)/?$ country-admin-city.php?country=$1&admin1code=$2&admin2code=$3&city=$4 [NC]
Upvotes: 1
Views: 53
Reputation: 785226
Have it like this:
# skip all files and directories from rewrite rules below
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^fishing-clubs/?$ - [L,NC]
RewriteRule ^fishing-clubs/([\w()-]+)/?$ /fishing-clubs/index.php?country=$1 [NC,L,QSA]
#worldwide
RewriteRule ^([\w()-]+)/?$ country-admin-city.php?country=$1 [NC,L,QSA]
RewriteRule ^([\w()-]+)/([\w()-]+)/?$ country-admin-city.php?country=$1&admin1code=$2 [NC,L,QSA]
RewriteRule ^([\w()-]+)/([\w()-]+)/([\w()-]+)/?$ country-admin-city.php?country=$1&admin1code=$2&admin2code=$3 [NC,L,QSA]
RewriteRule ^([\w()-]+)/([\w()-]+)/([\w()-]+)/([\w()-]+)/?$ country-admin-city.php?country=$1&admin1code=$2&admin2code=$3&city=$4 [NC,L,QSA]
Upvotes: 1