I have a series of mod_rewrite directives (shown below as Code 1) that run every server request through a custom PHP app.
Code 1
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /app/core.php [L,NC,QSA]
Before I get to the last step in the mod_rewrites, I need to change any request to mydomain.com to mydomain.org. Code 2 below shows what I am thinking but it does not work. The request gives me 500 Internal Server error.
Code 2
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mydomain\.com$
RewriteRule ^ http://mydomain.org%{REQUEST_URI}
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /app/core.php [L,NC,QSA]
Can someone offer a suggestion? Thanks
I asume your site is reachable by two domains, but you want all request to your site redirected to one of them. Then the correct code is:
You should place that code directly after the redirect line.
The second line makes sure that there is no redirect if no Host is given (to prevent a redirect loop in that case).
The [R=permanent,L] in the third line makes it a permanent redirect and prevents any further rule processing. The other rules will be processed once the redirect has taken place.
The full file would then be: