Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > ISPConfig 3 > Tips/Tricks/Mods

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #1  
Old 15th May 2009, 10:26
tio289 tio289 is offline
Member
 
Join Date: Mar 2009
Posts: 70
Thanks: 2
Thanked 14 Times in 9 Posts
Default Dynamic subdomains and non www to www

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
Code:
...
if(count($rewrite_rules) > 0) {
			$tpl->setVar('rewrite_enabled',1);
		} else {
			$tpl->setVar('rewrite_enabled',0);
		}
...
to this
Code:
...
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
Code:
...
<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)
Code:
    <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

Last edited by tio289; 26th November 2009 at 00:19.
Reply With Quote
Sponsored Links
  #2  
Old 8th November 2009, 09:15
enmi enmi is offline
Junior Member
 
Join Date: Nov 2009
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi the configuration files im opening are not looking exactly as your howto.. Have there been any changes?
Reply With Quote
  #3  
Old 8th November 2009, 18:50
Niels Niels is offline
Member
 
Join Date: Oct 2009
Posts: 52
Thanks: 5
Thanked 2 Times in 2 Posts
Default

Quote:
Originally Posted by tio289 View Post
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
Reply With Quote
  #4  
Old 8th November 2009, 19:09
enmi enmi is offline
Junior Member
 
Join Date: Nov 2009
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

can you show me your apache2_plugin.inc.php and vhost.conf.master files?
Reply With Quote
  #5  
Old 9th November 2009, 21:51
enmi enmi is offline
Junior Member
 
Join Date: Nov 2009
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

this is my edits and its not working...

apache2_plugin.inc.php:

Code:
   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:

Code:
<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'>
Reply With Quote
  #6  
Old 9th November 2009, 22:21
enmi enmi is offline
Junior Member
 
Join Date: Nov 2009
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

scoutlan.me.vhost

Code:
<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>
Reply With Quote
  #7  
Old 9th November 2009, 22:24
tio289 tio289 is offline
Member
 
Join Date: Mar 2009
Posts: 70
Thanks: 2
Thanked 14 Times in 9 Posts
Default

I dont try this domain, because is not registred

but place code on bottom, after this

Code:
<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.
Reply With Quote
  #8  
Old 25th November 2009, 11:28
blaster667 blaster667 is offline
Junior Member
 
Join Date: Nov 2009
Posts: 1
Thanks: 0
Thanked 1 Time in 1 Post
Smile

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
Reply With Quote
The Following User Says Thank You to blaster667 For This Useful Post:
Niels (25th November 2009)
  #9  
Old 25th November 2009, 20:31
enmi enmi is offline
Junior Member
 
Join Date: Nov 2009
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.
Reply With Quote
  #10  
Old 26th November 2009, 00:17
tio289 tio289 is offline
Member
 
Join Date: Mar 2009
Posts: 70
Thanks: 2
Thanked 14 Times in 9 Posts
 
Default

Quote:
Originally Posted by blaster667 View Post
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.
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 16:15.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.