Results 1 to 13 of 13

Thread: Installing Contao in a subdirectory

  1. #1
    User
    Join Date
    04-01-10.
    Posts
    289

    Default Installing Contao in a subdirectory

    Hello,

    I got a registrar for my domain name (ie mydomain.com) and a web hoster for my Contao website. My registrar is configured with my hoster's DNS.

    As I have many other things in the same place, I've uploaded Contao in a subdirectory at path www/site/

    Is there a way make http://www.mydomain.com and mydomain.com to go directly to mydomain.com/site/ ?

    Thanks a lot.

  2. #2
    Experienced user
    Join Date
    06-20-09.
    Posts
    1,311

    Default Re: Installing Contao in a subdirectory

    Yes, many.
    via a page redirect, via .htaccess file, via your server control panel (configuring depends what type of access/control panel you have). You're best to ask your host about this if you're unsure.

  3. #3
    User
    Join Date
    04-01-10.
    Posts
    289

    Default Re: Installing Contao in a subdirectory

    Thanks Ramjet.

    I contacted my host but their answer was first "put it at root" and finally "use DirectoryIndex site".
    But, with DirectoryIndex, I saw the files in the directory. And so on when I wanted to go to the admin page. I had to type : mydomain.com/site/contao/index.php

    Then I found "RedirectMatch permanent ^/$ http://mydomain.com/site/ but /site/ is still visible in the adress bar.
    An idea to hide it ?

  4. #4
    Community-Moderator xchs's Avatar
    Join Date
    06-19-09.
    Posts
    1,287

    Default Re: Installing Contao in a subdirectory

    Quote Originally Posted by charled
    Is there a way make http://www.mydomain.com and mydomain.com to go directly to mydomain.com/site/ ?
    Quote Originally Posted by charled
    but /site/ is still visible in the adress bar.
    An idea to hide it ?
    Yes. Go to your web administration area (from your hoster/provider) and map the relevant domain name to the subdirectory "site". That's all.

    After that, make sure to adapt the website path (e.g. by running the Contao Install Tool) and - if used - the "RewriteBase" in your server configuration file ".htaccess", respectively.
    Contao Community Moderator
    → Support options

  5. #5
    User
    Join Date
    04-01-10.
    Posts
    289

    Default Re: Installing Contao in a subdirectory

    Quote Originally Posted by xchs
    [
    Yes. Go to your web administration area (from your hoster/provider) and map the relevant domain name to the subdirectory "site". That's all.
    I'd like to but it seems not to be possible with my host. I can make redirections but only like xxxx.mydomain.com to theotherdomain.com. When I tried .mydomain.com (they put automatically the first .) to mydomain.com/site/ , the answer is : "Source and target have the same base url, this will result in an infinite loop".

    So, what can I do ?

    After that, make sure to adapt the website path (e.g. by running the Contao Install Tool) and - if used - the "RewriteBase" in your server configuration file ".htaccess", respectively.
    I ran again the Contao Install Tool but I don't find where to indicate the website path. Otherwise, I've found it in system/config/localconfig.php and it was good : $GLOBALS['TL_CONFIG']['websitePath'] = '/site/'; (but I don't know why

  6. #6
    Community-Moderator xchs's Avatar
    Join Date
    06-19-09.
    Posts
    1,287

    Default Re: Installing Contao in a subdirectory

    Quote Originally Posted by charled
    I ran again the Contao Install Tool but I don't find where to indicate the website path.
    By running the Contao Install Tool the Website Path is set automatically. There is no input field for this.

    Quote Originally Posted by charled
    Otherwise, I've found it in system/config/localconfig.php and it was good : $GLOBALS['TL_CONFIG']['websitePath'] = '/site/'; (but I don't know why
    Yes, actually, for your domain configuration this is right. But you want to get rid of the URL fragment "/site/", don't you?

    Can you tell us the name of the provider which hosts your site? What kind of Control Panel they are using?

    The easiest way would be - like mentioned by ramjet and me - to adapt this in the domain configuration by mapping the domain name to the corresponding subdirectory. Actually, this is set to the root "/" of your web space.

    Maybe an other way to get rid of this subfolder URL fragment would be to rewrite all specific requests from "http://www.example.com/site" to "http://www.example.com/". However, this requires that the Apache module "mod_rewrite" is available on the server (and of course activated for you)...
    Contao Community Moderator
    → Support options

  7. #7
    User
    Join Date
    04-01-10.
    Posts
    289

    Default Re: Installing Contao in a subdirectory

    Quote Originally Posted by xchs
    Quote Originally Posted by charled
    I ran again the Contao Install Tool but I don't find where to indicate the website path.
    By running the Contao Install Tool the Website Path is set automatically. There is no input field for this.
    ok. Nice.

    Quote Originally Posted by charled
    Otherwise, I've found it in system/config/localconfig.php and it was good : $GLOBALS['TL_CONFIG']['websitePath'] = '/site/'; (but I don't know why
    Yes, actually, for your domain configuration this is right. But you want to get rid of the URL fragment "/site/", don't you?[/quote]
    That's right.

    Can you tell us the name of the provider which hosts your site? What kind of Control Panel they are using?
    It's a french provider : ovh.com . I don't know the kinf of CP used. It's called manager (v3). I can be a self made one.

    The easiest way would be - like mentioned by ramjet and me - to adapt this in the domain configuration by mapping the domain name to the corresponding subdirectory. Actually, this is set to the root "/" of your web space.
    ok. I suppose I have to do it in the dns configuration panel (I only looked in redirections panel). I have other directories with programs like a forum (www/forum/ …) Is it a problem if I change the mapping ?

    Maybe an other way to get rid of this subfolder URL fragment would be to rewrite all specific requests from "http://www.example.com/site" to "http://www.example.com/". However, this requires that the Apache module "mod_rewrite" is available on the server (and of course activated for you)...
    ok. Perhaps I'd prefer this solution.
    1. What is the syntax for it, please ?
    2. To summerize, if I understand well, it have to choose between the mod_rewrite solution and the dns solution (former paragraph).

    Thanks for all.

  8. #8
    User
    Join Date
    04-01-10.
    Posts
    289

    Default Re: Installing Contao in a subdirectory

    Hello,

    sorry to ask it again but what is the syntax to get rid of /site for http://www.mydomain.com/site in .htaccess ?

    Thanks.

  9. #9
    New user
    Join Date
    07-19-11.
    Posts
    5

    Default Re: Installing Contao in a subdirectory

    Hi charled,
    I know I'm a bit late for your request, but I managed to solve this problem for my website, and I would like to share my experience.
    I've installed contao in a subdirectory ( let's call it dir0/) but I want that the url appearing in the browser nav-bar has to be http://www.mysite.com and not http://www.mysite.com/dir0/ for at least two reasons (search engines consistency with the old website, maintenance purposes).
    than I've edited the .htaccess file in the root of my web space (via ftp it should be called htdocs or something similar).
    I've tried several scripts over the web, but this is the only one that works well. the directives are:
    Code:
    <IfModule mod_rewrite.c>
    
      RewriteEngine On
      
      RewriteCond %{HTTP_HOST} ^mysite.com$ [OR]
      
      RewriteCond %{HTTP_HOST} ^www.mysite.com$
      
      RewriteCond %{REQUEST_URI} !^/dir0/
    
      #RewriteCond %{REQUEST_URI} !^/dir1/
      
      RewriteRule (.*) /dir0/$1
      
    </IfModule>
    let me explain the code: this solution requires the rewrite module, the ifModule line is there in order to avoid server errors in the case that the module required is missing from the apache installation. In a standard installation it's there, but maybe you can chech with a phpinfo() what modules are enabled.

    than the logic of the rewrite rule:
    the next two lines tell "I want that requests either pointing to mysite.com or http://www.mysite.com",
    the next line adds another condition: "the URI of these requests don't start with /dir0/" since I'm going to prepend "/dir0/", a URI which already has that path doesn't require to be modified
    than the last line prepends /dir0/ to the URI, therefore a request to mysite.com/page1.html will be served with the file htdocs/dir0/page1.html
    the commented line
    Code:
    #RewriteCond %{REQUEST_URI} !^/dir1/
    is useful if you have other resources in your webserver (eg. in another path /htdocs/dir1/) and you still want them to be available. But what happens if you have a directory such as /dir0/dir0/ ? or /dir0/dir1/ ? the webserver can't be sure of the destination of your request. If possible you have to avoid such particular cases.

    Once written and uploaded this .htaccess, you have to setup contao:
    BackEnd/settings/Global configuration/Relative path to the Contao directory --> let it empty since you don't want any /dir0/ in the path of the links (the rewrite rule should do everything by itself)

    .htaccess file in the contao installation dir - line 85 --> I didn't have to uncomment this line, therefore it remains #RewriteBase /0
    that's all.

    Now my personal request:
    would you or someone be so kind to check if the following bug occurs also with your site, since it's very strange and can't figure out what's the reason, but I'm sure it is related to the subfolder installation.
    I've some problem with the BE: some specific server generated links go nuts when I don't set BackEnd/settings/Global configuration/Relative path to the Contao directory to /dir0/ and I don't set the RewriteBase /0 (uncommented). This is exactly what I want to avoid as I said before.
    The links that behave strange are:
    * the "go back" link in the top-right area of an edit page, edit content of an article, edit whatever where there is only a go back link in the tl_buttons DIV:
    [attachment=1:37mhfnvv]precedente.jpg[/attachment:37mhfnvv]
    in these cases the link, instead of pointing to the referer of that page (eg. main.php?do=page), points always to main.php?do=settings
    this doesn't happen when the tl_buttons DIV contains other links, such as New element and Edit multiple
    [attachment=0:37mhfnvv]precedente2.jpg[/attachment:37mhfnvv]
    * the save and the save and close buttons of an edit context point always to main.php?do=settings.
    * the "go back" link in the top-right area of the page main.php?do=settings points always to main.php?do=page

    I suppose it's related with the getReferer function, maybe with the caching? I've tried many configurations in order to isolate the problem, but I found only that it disappear if i set the Relative path to the Contao directory[/i] to /dir0/
    ---
    Alessandro Proglio

  10. #10
    New user
    Join Date
    10-08-12.
    Posts
    1

    Default Re: Installing Contao in a subdirectory

    Hi!

    Maybe some of you guys are still registered and active. I have to push that thread, because I have the same/a similar problem:

    My hoster (world4you) doesn't allow to map the domain name to the corresponding subdirectory as the easiest (already mentioned in here) solution would be.
    The domain is from uniteddomains.

    My website is in a subdirectory "my_subfolder" and my domain is something like "my-domain.com".

    Instead of "www.my-domain.com/my_subfolder/overview.html" I'd like to have "www.my-domain.com/overview.html" written in the URL. I went to lots of tutorials...but I'm still not getting there how i could manage that with url rewriting and htaccess. Maybe someone could help me?

    At the moment, thats in the .htaccess on the root level:
    Code:
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^(www\.)?my-domain\.com
    RewriteRule ^$ /my_subfolder/ [R=301,L]
    And thats in my subdirectory .htaccess where contao is installed:
    Code:
    ##
    # Contao Open Source CMS
    # Copyright (C) 2005-2012 Leo Feyer
    #
    # Formerly known as TYPOlight Open Source CMS.
    #
    # This program is free software: you can redistribute it and/or
    # modify it under the terms of the GNU Lesser General Public
    # License as published by the Free Software Foundation, either
    # version 3 of the License, or (at your option) any later version.
    # 
    # This program is distributed in the hope that it will be useful,
    # but WITHOUT ANY WARRANTY; without even the implied warranty of
    # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    # Lesser General Public License for more details.
    # 
    # You should have received a copy of the GNU Lesser General Public
    # License along with this program. If not, please visit the Free
    # Software Foundation website at <http://www.gnu.org/licenses/>.
    #
    # PHP version 5
    # @copyright  Leo Feyer 2005-2012
    # @author     Leo Feyer <http://www.contao.org>
    # @license    LGPL
    ##
    
    ##
    # Disable ETags
    # @see http://developer.yahoo.com/performance/rules.html#etags
    ##
    FileETag None
    <IfModule mod_headers.c>
      Header unset ETag
    </IfModule>
    
    ##
    # Prevent access to the Contao template files
    ##
    <FilesMatch "\.(tpl|html5|xhtml)$">
      Order allow,deny
      Deny from all
    </FilesMatch>
    
    ##
    # Set the proper MIME types
    # @see https://github.com/h5bp/html5-boilerplate
    ##
    <IfModule mod_mime.c>
      # JavaScript
      AddType application/javascript              js jsonp
      AddType application/json                    json
      # Audio
      AddType audio/ogg                           oga ogg
      AddType audio/mp4                           m4a f4a f4b
      # Video
      AddType video/ogg                           ogv
      AddType video/mp4                           mp4 m4v f4v f4p 
      AddType video/webm                          webm
      AddType video/x-flv                         flv
      # SVG
      AddType image/svg+xml                       svg svgz
      AddEncoding gzip                            svgz
      # Webfonts
      AddType application/vnd.ms-fontobject       eot
      AddType application/x-font-ttf              ttf ttc
      AddType font/opentype                       otf
      AddType application/x-font-woff             woff
      # Assorted types
      AddType image/x-icon                        ico
      AddType image/webp                          webp
      AddType text/cache-manifest                 appcache manifest
      AddType text/x-component                    htc
      AddType application/xml                     rss atom xml rdf
      AddType application/x-web-app-manifest+json webapp
      AddType text/x-vcard                        vcf
      AddType application/x-shockwave-flash       swf
    </IfModule>
    
    ##
    # Gzip compression
    # @see https://github.com/h5bp/html5-boilerplate
    ##
    <IfModule mod_deflate.c>
      # Current Apache versions (>= 2.2)
      <IfModule filter_module>
        FilterDeclare   COMPRESS
        ...
        ...
        FilterChain     COMPRESS
        FilterProtocol  COMPRESS  DEFLATE change=yes;byteranges=no
      </IfModule>
      # Legacy Apache versions
      <IfModule !mod_filter.c>
        AddOutputFilterByType DEFLATE text/html text/plain text/css application/json
        AddOutputFilterByType DEFLATE application/javascript
        AddOutputFilterByType DEFLATE text/xml application/xml text/x-component
        AddOutputFilterByType DEFLATE application/xhtml+xml application/rss+xml application/atom+xml
        AddOutputFilterByType DEFLATE image/x-icon image/svg+xml application/vnd.ms-fontobject application/x-font-ttf font/opentype
      </IfModule>
    </IfModule>
    
    ##
    # Expires headers (for better cache control)
    # @see https://github.com/h5bp/html5-boilerplate
    ##
    <IfModule mod_expires.c>
      ExpiresActive on
      ExpiresByType text/cache-manifest           "access plus 0 seconds"
      ExpiresByType text/html                     "access plus 0 seconds"
      # Data
      ExpiresByType text/xml                      "access plus 0 seconds"
      ExpiresByType application/xml               "access plus 0 seconds"
      ExpiresByType application/json              "access plus 0 seconds"
      # Feed
      ExpiresByType application/rss+xml           "access plus 1 hour"
      ExpiresByType application/atom+xml          "access plus 1 hour"
      # Media: images, video, audio
      ExpiresByType image/gif                     "access plus 1 month"
      ExpiresByType image/png                     "access plus 1 month"
      ExpiresByType image/jpg                     "access plus 1 month"
      ExpiresByType image/jpeg                    "access plus 1 month"
      ExpiresByType image/x-icon                  "access plus 1 month"
      ExpiresByType video/ogg                     "access plus 1 month"
      ExpiresByType audio/ogg                     "access plus 1 month"
      ExpiresByType video/mp4                     "access plus 1 month"
      ExpiresByType video/webm                    "access plus 1 month"
      # HTC files  (css3pie)
      ExpiresByType text/x-component              "access plus 1 month"
      # Webfonts
      ExpiresByType application/x-font-ttf        "access plus 1 month"
      ExpiresByType font/opentype                 "access plus 1 month"
      ExpiresByType application/x-font-woff       "access plus 1 month"
      ExpiresByType image/svg+xml                 "access plus 1 month"
      ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
      # CSS and JavaScript
      ExpiresByType text/css                      "access plus 1 year"
      ExpiresByType application/javascript        "access plus 1 year"
    </IfModule>
    
    ##
    # Add a Vary Accept-Encoding header for the compressed resources. If you
    # modify the file types above, make sure to change them here accordingly.
    # @see http://developer.yahoo.com/performance/rules.html#gzip
    ##
    <IfModule mod_headers.c>
      <FilesMatch "\.(js|css|xml|gz)$">
        Header append Vary Accept-Encoding
      </FilesMatch>
    </IfModule>
    
    ##
    # URL rewriting
    ##
    <IfModule mod_rewrite.c>
      RewriteEngine On
    
      ##
      # Change the RewriteBase if your Contao installation is in a subdirectoy and
      # the rewrite rules are not working properly. Usage examples:
      #
      #   RewriteBase /contao-2.11.0
      #   RewriteBase /path/to/contao
      #
      # Depending on your server, you might have to remove the line entirely. 
      ##
      RewriteBase /my_subfolder
    
      ##
      # Uncomment the following lines and replace "domain.com" with your domain
      # name to redirect requests without "www" to the correct domain. 
      ##
      #RewriteCond %{HTTP_HOST} ^domain\.com [NC]
      #RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
    
      ##
      # If you cannot use mod_deflate, uncomment the following lines to load a
      # compressed .gz version of the aggregated Contao JavaScript and CSS files.
      ##
      #AddEncoding gzip .gz
      #<FilesMatch "\.js\.gz$">
      #  AddType "text/javascript" .gz
      #</FilesMatch>
      #<FilesMatch "\.css\.gz$">
      #  AddType "text/css" .gz
      #</FilesMatch>
      #RewriteCond %{HTTP:Accept-encoding} gzip
      #RewriteCond %{REQUEST_FILENAME} \.(js|css)$
      #RewriteCond %{REQUEST_FILENAME}.gz -f
      #RewriteRule ^(.*)$ $1.gz [QSA,L]
    
      ##
      # Do not rewrite requests for static files or folders such as style sheets,
      # images, movies or text documents. Do not add the URL suffix here!
      ##
      <FilesMatch "\.(htm|php|js|css|htc|png|gif|jpe?g|ico|xml|csv|txt|swf|flv|eot|woff|svg|ttf|pdf|gz)$">
        RewriteEngine Off
      </FilesMatch>
    
      ##
      # By default, Contao adds ".html" to the generated URLs to simulate static
      # HTML documents. If you change the URL suffix in the back end settings, make
      # sure to change it here accordingly!
      #
      #   RewriteRule .*\.html$ index.php [L]   # URL suffix .html
      #   RewriteRule .*\.txt$ index.php [L]    # URL suffix .txt
      #   RewriteRule .*\.json$ index.php [L]   # URL suffix .json
      #
      # If you do not want to use an URL suffix at all, you have to add a second
      # line to prevent URLs that point to folders from being rewritten (see #4031).
      #
      #   RewriteCond %{REQUEST_FILENAME} !-d
      #
      # If you are using mod_cache, it is recommended to use the RewriteRule below,
      # which adds the query string to the internal URL:
      # 
      #   RewriteRule (.*\.html)$ index.php/$1 [L]
      #
      # Note that not all environments support mod_rewrite and mod_cache.
      ##  
    
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteRule .*\.html$ index.php [L]
    
      ##
      # The following rules are required if you want to pass the language as first
      # URL parameter (added in Contao 2.11). The first rule rewrites an empty URL
      # to the front end controller, the second one adds a missing trailing slash.
      ##
      RewriteRule ^[a-z]{2}/$ index.php [L]
      RewriteRule ^([a-z]{2})$ $1/ [R=301,L]
    
    
    </IfModule>
    thanks for any help in advance!

  11. #11
    User
    Join Date
    05-12-14.
    Posts
    72

    Default

    [QUOTE=xchs;89191]By running the Contao Install Tool the Website Path is set automatically. There is no input field for this.

    I set the root to the subfolder, but when i try to access the contao install tool i now get a 404 error.
    If i set my root back to my top level domain again, i can regain access.

    But if i have set my root to the sub folder where contao is installed (i.e..mydomain.com/contao3), why can't i access the install tool anymore?

  12. #12
    User
    Join Date
    07-23-10.
    Posts
    86

    Default

    mydomain.com/contao3
    Just let contao3 away ...when you point the Domain on the Subfolder your root ist your domainname.

    So, mydomain.com/contao/install.php would be the install tool and the backend mydomain.com/contao.

    I you use rewrite the URL (without index.php in your URL), you have to change the rewrite Base in the .htaccess to "/" (remove /contao3).
    This will not be done automatically with the install tool.

  13. #13
    User
    Join Date
    05-12-14.
    Posts
    72

    Default

    Cheers ciaobella,

    i figured this out about 3 seconds after id posted. :/ But i didn't do anything to the htaccess file. Just figured out i was calling the wrong directory to run the install tool again.


    Sometimes i think my brain is not in my head.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •