[SOLVED] Rewrite rules nightmare - help desperately needed!

I’ve just updated my site to cover multiple countries. All URLs now start with two letter country code, eg.


/uk/takeaway/fat_bobs

was previously


/takeaway/fat_bobs

.

I need to do a 301, permanent redirect, on these old URLs (sending them all to the uk country code). I simply can’t work out the mod_rewrite rule for this. I’ve tried loads, and just get an infinite loop of redirects.

Current .htaccess - site is live at www.thebigeat.com if you want to test it.




Options +FollowSymLinks

IndexIgnore */*

RewriteEngine on

RewriteBase /

AddDefaultCharset UTF-8





# RewriteRule ^main/browse_cities$ /uk/site/browseCities [R=301,L]


# Rewrite all old URLs to include UK countryCode

# RewriteRule


# if a directory or a file exists, use it directly

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d


RewriteRule ^(\w{3,}.*)$ /uk/$1 [R=301,L]


RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d


# otherwise forward it to index.php

RewriteRule . index.php



Here’s the file that worked for me in the end:




Options +FollowSymLinks

IndexIgnore */*

RewriteEngine on

RewriteBase /

AddDefaultCharset UTF-8





# RewriteRule ^main/browse_cities$ /uk/site/browseCities [R=301,L]


# Rewrite all old URLs to include UK countryCode

# RewriteRule


# if a directory or a file exists, use it directly

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d


RewriteRule ^([^/]{3,}.*)$ /uk/$1 [R=301,L]


RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d


# otherwise forward it to index.php

RewriteRule . index.php