Right now I have the following code to redirect all non-www URLs to www URLs:
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
Besides that redirection, I also want to redirect all calls to /dev/ to dev.example.com. I've tried a bunch of different approaches but nothing has worked (the few that get close like ReplaceMatch will only redirect to the dev.example.com bit and will leave the rest as a query string).
Any ideas?
EDIT: Here's the full .htaccess for the root folder (a few rewritten for privacy reasons):
ErrorDocument 404 /404.html
AddType application/x-httpd-php .json
AddType application/x-httpd-php .xml
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
# disables image hotlinking
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?example\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !google\. [NC]
RewriteCond %{HTTP_REFERER} !search\?q=cache [NC]
RewriteRule .*\.(jpe?g|gif|bmp|png)$ - [F]
# Stop htaccess rules from accessing these areas of the website.
RewriteRule ^(banner|boxart|cgi-bin|content|forums|includes|newsimages|newsimg|sidebar|union-files|google5e645385256c3a63.html) - [L]
# Redirects /page URLs to /page/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\.[^./]+$
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) /$1/ [R=301,L]
# Redirect old URLs to their new URLs
RewriteRule ^reviews/badurl--43.html$ http://www.gamingunion.net/reviews/goodurl--43.html [R=301,NC]
# Redirect non-WWW to WWW
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
RedirectMatch 301 ^/dev/(.*)$ http://dev.example.com/$1
# URL Directory Redirects
RewriteRule ^([^/]*)/$ /index.php?p=$1&urltype=slash [L,QSA]
RewriteRule ^([^/]*)/$ /index.php?p=$1&urltype=slash [L,QSA]
RewriteRule ^([^/]*)/([^/]*)/$ /index.php?p=$1&lv1d=$2 [L,QSA]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/$ /index.php?p=$1&lv1d=$2&lv2d=$3 [L,QSA]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)/$ /index.php?p=$1&lv1d=$2&lv2d=$3&lv3d=$4 [L,QSA]
# URL File Redirects
RewriteRule ^([^/]*)\.html$ /index.php?p=$1&urltype=dot [L,QSA]
RewriteRule ^([^/]*)/([^/]*)\.html$ /index.php?p=$1&lv1p=$2 [L,QSA]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)\.html$ /index.php?p=$1&lv1d=$2&lv2p=$3 [L,QSA]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)\.html$ /index.php?p=$1&lv1d=$2&lv2d=$3&lv3p=$4 [L,QSA]
# For servers that support output compression, you should pick up a bit of speed but un-commenting the following lines.
php_flag zlib.output_compression On
php_value zlib.output_compression_level 5
The one in /dev/ is basically the same as this one, except that it has a password protection bit at the top and has a few redirects for some image folders that only reside on the root of the server.