I apologize ahead of time that this might be a common question, however I've spent 3-4 hours already on solutions which don't quite fix the problem.I have a site and it is moving to a different domain, the problem is--the site is paired with software which looks for: http://site/version. Using a simple 301 redirect won't work because it'll get '301 Moved Permanently' instead of the actual data. So I thought.. ok--I made version.php which has:<? echo file_get_contents('http://newsite/version'); ?>So the idea is simple: When one requests http://site/version, give them http://site/version.php, else: redirect everything to http://newsite/$1What I got was something like this:RewriteEngine OnRewriteBase /RewriteRule ^/version$ /version.phpRewriteCond %{HTTP_HOST} site\.com$ [NC]RewriteCond %{REQUEST_URI} !^version$RewriteRule ^(.*)$ http://newsite.com/$1 [R=301]I am no master at mod_rewrite rules, this is just what I hacked together and it doesn't work or I wouldn't be here. If someone who knows them better than I can help, I'd be very grateful. Thank you in advance.
.htaccess problems with redirection
php;htaccess;redirects;mod rewrite
I think you have the correct idea, but the directory prefix (/) is probably the main thing that is causing problems. Try the following...RewriteEngine OnRewriteBase /RewriteCond %{HTTP_HOST} ^site\.com$ [NC]RewriteRule ^version$ /version.php [L]RewriteCond %{HTTP_HOST} ^site\.com$ [NC]RewriteCond %{REQUEST_URI} !^/versionRewriteRule (.*) http://newsite.com/$1 [R=301,L]The RewriteRule pattern in per-directory .htaccess files is matched against the URL less the directory prefix (ie. version, not /version), so your pattern would never match.Conversely the REQUEST_URI variable always includes the full URI, including the directory prefix (/). And in this case, it is likely to be the rewritten URL, ie. /version.php and not /version. Although I simply removed the end-of-string placeholder ($) so it will catch both anyway - assuming you don't have other URLs that start /version?EDIT: Note that if site.com and newsite.com are completely separate sites (as suggested in comments) and no other domains are parked at site.com then you don't need to check the %{HTTP_HOST} and these RewriteCond directives can be removed.