views:

175

answers:

1

My homepage is located at www.nazgulled.net and I bought a new domain which is www.ricardoamaral.net. Both these domains point to the same exact server.

I'm having two problems with the redirection, my current code is this:

RewriteCond %{HTTP_HOST} ^(www\.)?nazgulled\.net [NC]
RewriteRule ^(.*)$ http://www.ricardoamaral.net/$1 [L]

For now I'm just testing but the idea is to replace [L] with [L,R=301] when I'm ready to move the whole thing, just so you know.

Anyway...

1) This is not working, when I try it, I can't access "nazgulled.net", it gives me a "server internal error" and I don't understand why... I don't understand why because if replace "ricardoamaral.net" by "google.com", the redirect works just fine :/

2) I have a few subdomains and I would like to redirect everything in those too. My first choice is to add different rewrite conditions/rules for each of the subdomains but that takes a lot of manual code and if the user types some subdomain that doesn't exist, they don't be redirect it and I also want that.

+1  A: 

For 1, you can use something like this instead:

<VirtualHost *:80>
  ServerAdmin [email protected]
  ServerName nazgulled.net
  ServerAlias www.nazgulled.net
  Redirect permanent / http://www.ricardoamaral.net/
</VirtualHost>

I use a similar configuration and it works perfectly, keeping query parameters, paths, etc.

Regarding your own rewrite rule, I want to note that you may lose your query params if you don't include QSA.

To diagnose internal server errors, just have a look at the log file provided by your ErrorLog directive within your vhost, or a global one, depending on your configuration. It should give you the exact reason for the error.

Artem Russakovskii
But that won't solve problem #2 right? But if I use this solution, I don't need to care about the QSA flag right? I know I can diagnose them like that, the problem is that the url to access my domain panel is not working lol, I must contact my domain admin...
Nazgulled
You'd probably be better off handling #2 the same way as I suggested. I definitely welcome a different suggestion.
Artem Russakovskii
I would have to add a VirtualHost for each subdomain that way and that's what I want to avoid...
Nazgulled