Forum Moderators: phranque

Message Too Old, No Replies

.htaccess redirect subdomain

subdomain to index.php?subdomain

         

cyppher

2:27 pm on Jun 8, 2006 (gmt 0)

10+ Year Member



Hello all,

I've searched and tried, but I can't get this problem solved:

I have a main domain (ie. maindomain.nl) on which a CMS is installed. The CMS uses article categories accessed on the variable after index.php (ie. index.php?category)

Now I have another domain, which lands directly on my maindomain.nl (ie. domain2.nl -> maindomain.nl). And also I have a subdomain for this domain (ie. subdomain.domain2.nl) that I want to redirect to maindomain.nl/index.php?subdomain

In .httaccess I want to rewrite URL's:
*www.domain2.nl -> www.maindomain.nl/index.php?media
* subdomain.domain2.nl -> www.maindomain.nl/index.php?subdomain
* subdomain2.domain2.nl -> www.maindomain.nl/index.php?subdomain2

I added (generated) code to .htaccess in the httpdocs folder on the webserver.
However, when I enter the URL maindomain.nl, I get a server error (500). This error also appears when I enter subdomain.domain2.nl

I guess something in this code is wrong, I can't figure out what, so I removed the code... See below for that code.

Does anyone know how to get the right code?


RewriteEngine On

RewriteCond %{HTTP_HOST} ^maindomain.nl$
RewriteCond %{REQUEST_URI}!^/?media/
RewriteRule (.*) /?media/$1

RewriteCond %{HTTP_HOST} ^cuba.maindomain.nl$
RewriteCond %{REQUEST_URI}!^/?cuba/
RewriteRule (.*) /?cuba/$1

RewriteCond %{HTTP_HOST} ^klant.maindomain.nl$
RewriteCond %{REQUEST_URI}!^/?klant/
RewriteRule (.*) /?klant/$1

also I tried this, but it didn't work:
# URL forwarding
# www.maindomain.nl -> www.domain2.nl/index.php?media
RewriteCond %{HTTP_HOST}
^www\.[^.]+\.www\.maindomain\.nl$
RewriteRule ^(.+) %{HTTP_HOST}$1 [C]
RewriteRule ^www\.([^.]+)\.www\.domain2\.nl(.*) /index.php?media$1$2

[edited by: jdMorgan at 11:03 pm (utc) on June 8, 2006]
[edit reason] Removed specifics per TOS. [/edit]

jdMorgan

11:16 pm on Jun 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'd suggest a few adjustments. However, you didn't say if you have *any* working rewriterules, or describe the error message in your error log -- a very useful bit of information.

In .httaccess I want to rewrite URL's:
* www.domain2.nl -> www.maindomain.nl/index.php?media
* subdomain.domain2.nl -> www.maindomain.nl/index.php?subdomain
* subdomain2.domain2.nl -> www.maindomain.nl/index.php?subdomain2

So let's take just the first of those requirements, and see if we can get that working:


# Required on many servers to enable mod_rewrite
Options +FollowSymLinks
# Turn on rewriting engine
RewriteEngine On
#
# www.domain2.nl (or domain2.nl) -> www.maindomain.nl/index.php?media
RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.nl
RewriteCond %{REQUEST_URI} !^/index\.php
RewriteRule .* /index.php?media [L]

Jim