We have two main subdomains on our site: www.example.edu and php.example.edu. Virtually all of our content is on www.example.edu, but there are a few standalone apps hosted on php.example.edu. www.example.edu is maintained by non-technical users via a CMS that forces root-relative URLs in most cases. We would like to include departments' navigation links in their apps on php.example.edu, but those links obviously don't work as root-relative URLs. We would like to avoid server-side parsing/rewriting of sidenav files.What we would like to do is to replace all 404s on php.example.edu with 301s to the same path on www.example.edu. I've tried a few different RewriteCond/RewriteRule setups, most recentlyRewriteEngine OnRewriteCond %{REQUEST_URI} !-fRewriteCond %{REQUEST_URI} !-dRewriteRule ^(.*) http://www.example.edu/$1 [R=302,L]but none of them have worked yet, either ending in false-positives or 500 errors. Any suggestions?
Replace 404 with 301 to other subdomain
apache;301 redirect;http code 500
You have to use correct variables when writing the rule: %{REQUEST_URI} !-f makes no sense (unless requested URL = exact physical path on server -- 0.000001% chance to have such unusual setup).You need to use %{REQUEST_FILENAME} instead of %{REQUEST_URI}. The difference is big: for php.example.edu/hello/kitten.php the %{REQUEST_URI} variable will be equal /hello/kitten.php while %{REQUEST_FILENAME} will have full physical path on file system, e.g. /www/php.example.com/httpdocs/hello/kitten.php (assuming that website root is /www/php.example.com/httpdocs). I highly doubt that you will have /hello/kitten.php file in place (relative to the file system root, of course, and not website).Proper rule should look like this:RewriteEngine OnRewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule ^(.*)$ http://www.example.edu/$1 [R=302,L]or RewriteEngine OnRewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule .* http://www.example.edu%{REQUEST_URI} [R=302,L]P.S.Don't forget to change 302 (Found) to 301 (Permanent redirect) after finishing testing (ensuring that rule is working fine).