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
IMPORTANT!!!
For correct function you must change the option Auto-subdomain to * in website configuration
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.
blaster667
25th November 2009, 12:28
Hi.
This feature is included in ISPConfig 3.0.1.3. To redirect HTTP queries from yourdomain.com to www.yourdomain.com change the option "Auto-subdomain" to "*" in website configuration.
Max
enmi
25th November 2009, 21:31
would that work for folders also?
like for example "yourdomain.com/test"
Would also be available at "test.yourdomain.com" because thats the function im really interested in.
tio289
26th November 2009, 01:17
Hi.
This feature is included in ISPConfig 3.0.1.3. To redirect HTTP queries from yourdomain.com to www.yourdomain.com change the option "Auto-subdomain" to "*" in website configuration.
Max
Yes, I forgot. This option you must select to "*".
ENMI:
yourdomain.com/sd_test will be available at "test.yourdomain.com", but you can edit rewriterules to remove sd_ prefix.
enmi
4th March 2010, 10:50
Hi! i finally got this to work. The main problem i had was the fact that i was using the ispconfig server as a name server for my clients. so outside my LAN it works but only inside if i remove the server from the dns-settings.
Nicram
21st March 2010, 21:10
There is 3.0.2 around now.
Is there any simple way to make website auto redirecting from example.com to www.example.com ? Without editing any files?
I try to use web alias, or selecting (in website domain) "*" as automatic subdomain or "www" but it did not transfer from example.com to www.example.com. How to do that?
till
21st March 2010, 21:32
There is no need to edit any files, neither in 3.0.2 nor any version before that. Just add the following lines in the apache directives field of the website were you want to get this automatic rewrite:
RewriteEngine On
RewriteCond %{HTTP_HOST}//s%{HTTPS} ^[^w][^w][^w][^.].*//((s)on¦s.*) [NC]
RewriteRule ^ http%2://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
See here for details:
http://www.webmasterworld.com/forum92/5253.htm
Nicram
21st March 2010, 21:43
Thanks :) Too bad no such option in ispconfig :)
Uh i was happy too fast. While it is loading website from www.example.com the address do not change in browser address bar.
But well i figured it out that wordpress do it automatically if i use www.example.com as domain in it's configuration, so will try to check how it is doing that, and maybe i will be able to do same with my sites :)
vBulletin® v3.8.7, Copyright ©2000-2012, vBulletin Solutions, Inc.