• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

I'd like a subdomain to be redirected to the domain httpdocs directory

Do not remove the *.domain.com DNS entry for the domain.

I prefer to do it slightly differently (not chaining them with the [OR]. It gives me more flexibility by having discreet sections for each subdomain for later changes.

For example:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteMap lowercase int:tolower

ServerAlias sub1.domain.com
RewriteCond %{HTTP_HOST} ^sub1.domain.com$
RewriteCond %{REQUEST_URI} !error_docs
RewriteRule ^/(.*) http://www.domain.com/$1 [L,R]

ServerAlias sub2.domain.com
RewriteCond %{HTTP_HOST} ^sub2.domain.com$
RewriteCond %{REQUEST_URI} !error_docs
RewriteRule ^/(.*) http://www.domain.com/$1 [L,R]

</IfModule>


This should redirect 'sub1.domain.com' and 'sub2.domain.com' to 'www.domain.com', and is easier to modify at a later date if needed.
 
That worked for the subdomains, thanks.

Could a similar thing be done with TLDs?
 
More than likely it can, give me an example of what you are thinking of.

There was another post recently regarding parked domains ( .be .de .nl ) and redirecting them to separate folders under the main domain ( .com ). This was simple since they were parked onto the main domain, so only a single vhost.conf file had to be modified. If the domains are not parked, then each domain's vhost.conf file would need to be modified to redirect them elsewhere.

The mod_rewrite module is very powerful in what you can do, it is just a matter of clarifying exactly what you wish to accomplish and writing the conditions and rules properly.
 
well im using a CMS that allows "multisites" and allows multiple sites to be run from the same directory, using different tables etc.

So i can have www.books.com and would like to maybe have www.movies.com (for example) configured to use the same directory.

The cms uses mod_rewrite etc to achieve this.
 
Ah, then you've already answered your own question. If the CMS already handles it using mod_rewrite, then once you have it all setup, just look at the rewrite conditions and rules which it sets up.
 
The CMS handles the output so that the domains look seperate.

However i have to setup the server so that when i enter www.books.com it looks to /var/www/vhots/movies.com/htdocs
 
Ok, see if this post of mine may help you on doing it. Skip about the first 90% of the thread, look for my post on 26th August 2005 04:12 AM "Same server cross domain redirection". If the AliasMatch doesn't work for the CMS, then try modifying the example I give for "Separate servers, domain redirection" which are actual rewrites.

http://forum.plesk.com/showthread.php?threadid=25799&highlight=cross+AND+domain+AND+redirect

Substitute "www.books.com" for "sub.thisdomain.tld" and "www.movies.com" for "sub.otherdomain.tld"

Also substitute your /var/www/vhosts/ for /home/httpd/vhosts/

And (as always) after making any changes, you need to do the following:

/usr/local/psa/admin/bin/websrvmng -u --vhost-name=books.com
(or which ever domain is the one being redirected)

and restart the apache service (service httpd restart)
 
ok tested the following:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteMap lowercase int:tolower

ServerAlias sub1.domain.com
RewriteCond %{HTTP_HOST} ^sub1.domain.com$
RewriteCond %{REQUEST_URI} !error_docs
RewriteRule ^/(.*) /home/httpd/vhosts/domain.com/httpdocs$1 [L,R]

ServerAlias sub2.domain.com
RewriteCond %{HTTP_HOST} ^sub2.domain.com$
RewriteCond %{REQUEST_URI} !error_docs
RewriteRule ^/(.*) /home/httpd/vhosts/domain.com/httpdocs$1 [L,R]

</IfModule>

And on going to sub1 or sub2.domain.com i get a popup error:

Redurection limit for this URL exceeded, Unable to load the requested page.

It works if i put in http://www.domain.com/ instead of the server folder.

Is there a way to make it so that it would look to the server folder?
 
You would have to have something more similar to the following:
Code:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteMap lowercase int:tolower

ServerAlias sub1.domain.com
RewriteCond %{HTTP_HOST} ^sub1.domain.com$
[b]RewriteCond %{HTTP_URI} !^/subdomains/sub1/[/b]
RewriteCond %{REQUEST_URI} !error_docs
[b]RewriteRule (.*) /subdomains/sub1/$1[/b]

ServerAlias sub2.domain.com
RewriteCond %{HTTP_HOST} ^sub2.domain.com$
[b]RewriteCond %{HTTP_URI} !^/subdomains/sub2/[/b]
RewriteCond %{REQUEST_URI} !error_docs
[b]RewriteRule (.*) /subdomains/sub2/$1[/b]

</IfModule>

This assumes you have the subdomains located at:

/home/httpd/vhosts/domain.com/httpdocs/subdomains/sub1
/home/httpd/vhosts/domain.com/httpdocs/subdomains/sub2

Please pay attention to what is in bold.
 
Would it not work to simply create an A record for your subdomain then create a vhost.conf/vhost_ssl.conf with a simple ServerAlias?

For example:

Create the A record for sub1.yourdomain.com
Code:
sub1.yourdomain.com.   A   xxx.xxx.xxx.xxx

Place the following in your /home/httpd/vhosts/yourdomain.com/conf/vhost.conf
Code:
ServerAlias sub1.yourdomain.com
 
I'm not sure the ServerAlias directive would work for his situation, it looks like he's trying to do a Cross Domain type redirection.

He's got 2 domains (books.com and movies.com) and he's trying to get them both to use the same docroot of one domain, but 'appear' to be separate, at least that's what he posted earlier....

I could be wrong about the ServerAlias, I've never used that method for attempting a cross domain type redirect/proxy, however the mod_rewrite can and does handle it properly, although I have not really taken a good look at the link he posted.

Actually, looking at his latest rewrite post, now I'm not sure if he's still working on the cross domain thing or not. Ok, I am officially confused as to what he is trying to accomplish. LOL
 
Back
Top