PDA

View Full Version : Dynamic subdomains and non www to www


tio289
15th May 2009, 11:26
UPDATED
hello I edit some files to do this:

first you must edit /usr/local/ispconfig/server/plugins-available/apache2_plugin.inc.php

edit this lines

...
if(count($rewrite_rules) > 0) {
$tpl->setVar('rewrite_enabled',1);
} else {
$tpl->setVar('rewrite_enabled',0);
}
...

to this

...
if(count($rewrite_rules) > 0) {
$tpl->setVar('rewrite_enabled',1);
} else {
$tpl->setVar('rewrite_enabled',0);
}
$tpl->setVar('rewrite_domain',str_replace('.', '\.', $data['new']['domain']));
...

then change file /usr/local/ispconfig/server/conf/vhost.conf.master

change this

...
<tmpl_if name="rewrite_enabled">

RewriteEngine on
<tmpl_loop name="redirects">
RewriteCond %{HTTP_HOST} ^<tmpl_var name='rewrite_domain'> [NC]
RewriteRule ^/(.*)$ <tmpl_var name='rewrite_target'>$1 <tmpl_var name='rewrite_type'>
</tmpl_loop>
</tmpl_if>
...

(we remove IF)
to this in both virtual hosts (80 and 443 too)

<IfModule mod_rewrite.c>
RewriteEngine on

RewriteCond %{http_host} ^<tmpl_var name='rewrite_domain'> [nc]
RewriteRule ^(.*)$ http://www.<tmpl_var name='domain'>$1 [r=301,nc]

RewriteCond %{HTTP_HOST} ^www\.([^.]+)\.<tmpl_var name='rewrite_domain'> [nc]
RewriteRule ^(.*)$ http://%1.<tmpl_var name='domain'>$1 [r=301,nc]

RewriteCond %{REQUEST_URI} !^/sd_
RewriteCond %{HTTP_HOST} !^www\.<tmpl_var name='rewrite_domain'> [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.<tmpl_var name='rewrite_domain'>
RewriteRule (.*) /sd_%1/$1 [L]

<tmpl_loop name="redirects">
RewriteCond %{HTTP_HOST} ^<tmpl_var name='rewrite_domain'> [NC]
RewriteRule ^/(.*)$ <tmpl_var name='rewrite_target'>$1 <tmpl_var name='rewrite_type'>
</tmpl_loop>
</IfModule>

in virtual host 443 change http:// to https://

now domain.com will be redirected (301) to www.domain.com

and if in domain folder create folder sd_example will be accessible on example.domain.com and www.example.domain.com will be redirected (301) to example.domain.com

There are my files

http://www.free-lance.sk/apache2_plugin.inc.php.txt

http://www.free-lance.sk/vhost.conf.master.txt

enmi
8th November 2009, 10:15
Hi the configuration files im opening are not looking exactly as your howto.. Have there been any changes?

Niels
8th November 2009, 19:50
and if on domain folder create folder sd_example will be accessible on example.domain.com

I have just tried and it redirected to www.example.domain.com

enmi
8th November 2009, 20:09
can you show me your apache2_plugin.inc.php and vhost.conf.master files?

enmi
9th November 2009, 22:51
this is my edits and its not working...

apache2_plugin.inc.php:

if(count($rewrite_rules) > 0) {
$tpl->setVar('rewrite_enabled',1);
} else {
$tpl->setVar('rewrite_enabled',0);
}
$tpl->setVar('rewrite_domain',str_replace('.', '\.', $data['new']['domain']));

$tpl->setLoop('redirects',$rewrite_rules);


and the vhost.conf.master:

<VirtualHost <tmpl_var name='ip_address'>:80>

<IfModule mod_rewrite.c>
RewriteEngine on

RewriteCond %{http_host} ^<tmpl_var name='rewrite_domain'> [nc]
RewriteRule ^(.*)$ http://www.<tmpl_var name='domain'>$1 [r=301,nc]

RewriteCond %{HTTP_HOST} ^www\.([^.]+)\.<tmpl_var name='rewrite_domain'> [nc]
RewriteRule ^(.*)$ http://%1.<tmpl_var name='domain'>$1 [r=301,nc]

RewriteCond %{REQUEST_URI} !^/sd_
RewriteCond %{HTTP_HOST} !^www\.<tmpl_var name='rewrite_domain'> [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.<tmpl_var name='rewrite_domain'>
RewriteRule (.*) /sd_%1/$1 [L]
</IfModule>

<tmpl_if name='php' op='==' value='suphp'>
DocumentRoot <tmpl_var name='web_document_root'>
</tmpl_else>
<tmpl_if name='php' op='==' value='cgi'>
DocumentRoot <tmpl_var name='web_document_root'>
</tmpl_else>
DocumentRoot <tmpl_var name='web_document_root_www'>

.......

# SSL Vhost
################################################## #########

<VirtualHost <tmpl_var name='ip_address'>:443>

<IfModule mod_rewrite.c>
RewriteEngine on

RewriteCond %{http_host} ^<tmpl_var name='rewrite_domain'> [nc]
RewriteRule ^(.*)$ https://www.<tmpl_var name='domain'>$1 [r=301,nc]

RewriteCond %{HTTP_HOST} ^www\.([^.]+)\.<tmpl_var name='rewrite_domain'> [nc]
RewriteRule ^(.*)$ https://%1.<tmpl_var name='domain'>$1 [r=301,nc]

RewriteCond %{REQUEST_URI} !^/sd_
RewriteCond %{HTTP_HOST} !^www\.<tmpl_var name='rewrite_domain'> [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.<tmpl_var name='rewrite_domain'>
RewriteRule (.*) /sd_%1/$1 [L]
</IfModule>

<tmpl_if name='php' op='==' value='suphp'>
DocumentRoot <tmpl_var name='web_document_root'>
</tmpl_else>
<tmpl_if name='php' op='==' value='cgi'>
DocumentRoot <tmpl_var name='web_document_root'>

enmi
9th November 2009, 23:21
scoutlan.me.vhost

<Directory /var/www/scoutlan.me>
AllowOverride None
Order Deny,Allow
Deny from all
</Directory>

<VirtualHost *:80>

<IfModule mod_rewrite.c>
RewriteEngine on

RewriteCond %{http_host} ^scoutlan\.me [nc]
RewriteRule ^(.*)$ http://www.scoutlan.me$1 [r=301,nc]

RewriteCond %{HTTP_HOST} ^www\.([^.]+)\.scoutlan\.me [nc]
RewriteRule ^(.*)$ http://%1.scoutlan.me$1 [r=301,nc]

RewriteCond %{REQUEST_URI} !^/sd_
RewriteCond %{HTTP_HOST} !^www\.scoutlan\.me [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.scoutlan\.me
RewriteRule (.*) /sd_%1/$1 [L]
</IfModule>

DocumentRoot /var/www/scoutlan.me/web

ServerName scoutlan.me
ServerAlias *.scoutlan.me
ServerAdmin webmaster@scoutlan.me

ErrorLog /var/log/ispconfig/httpd/scoutlan.me/error.log

ErrorDocument 400 /error/400.html
ErrorDocument 401 /error/401.html
ErrorDocument 403 /error/403.html
ErrorDocument 404 /error/404.html
ErrorDocument 405 /error/405.html
ErrorDocument 500 /error/500.html
ErrorDocument 503 /error/503.html

<Directory /var/www/scoutlan.me/web>
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all

# ssi enabled
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
Options +Includes
</Directory>
<Directory /var/www/clients/client5/web7/web>
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all

# ssi enabled
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
Options +Includes
</Directory>

# cgi enabled
<Directory /var/www/clients/client5/web7/cgi-bin>
Order allow,deny
Allow from all
</Directory>
ScriptAlias /cgi-bin/ /var/www/clients/client5/web7/cgi-bin/
AddHandler cgi-script .cgi
AddHandler cgi-script .pl
# suexec enabled
SuexecUserGroup web7 client5
# php as fast-cgi enabled
<Directory /var/www/scoutlan.me/web>
AddHandler fcgid-script .php .php3 .php4 .php5
FCGIWrapper /var/www/php-fcgi-scripts/web7/.php-fcgi-starter .php
Options +ExecCGI
AllowOverride all
Order allow,deny
Allow from all
</Directory>



</VirtualHost>

tio289
9th November 2009, 23:24
I dont try this domain, because is not registred

but place code on bottom, after this


<Directory /var/www/clients/client5/web7/web>
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all

# ssi enabled
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
Options +Includes
</Directory>


AllowOverride All is important option.