Website rewrite. How to make a subdomain act like a subdirectory

Discussion in 'Installation/Configuration' started by fatorXb2, May 23, 2015.

  1. fatorXb2

    fatorXb2 New Member

    Hi guys,

    I'm using ISPConfig 3 since last year and everything is great.
    Could someone tell me please how to solve this issue.

    I installed a Wordpress website in a subdomain, let's say: http://en.domain.com
    But now I have found that is not a good idea from a SEO point of view, so I want to change that to http://domain.com/en/

    I opt for NginX as a web server and already tried some rewrite rules, but I can't figure out how to make all my pages look like http://domain.com/en/tech (tech is just an example), so people can access my website by http://en.domain.com/tech and http://domain.com/en/tech

    If I use rewrite rules it does redirect but the address changes to http://en.domain.com but that is not what I realy want

    Is that any alternative to do this on ISPConfig panel or do I have to reinstall the website on a subdirectory??

    Thanks any help.
     
  2. kephra

    kephra Member

    I do this with some of my sites:

    Options +FollowSymLinks -Multiviews
    RewriteEngine on
    RewriteBase /
    #
    # Canonicalize the hostname
    RewriteCond www.%{HTTP_HOST} ^(www)\.(example\.com) [OR]
    RewriteCond %{HTTP_HOST} ^www\.([^.]+)\.(example\.com) [OR]
    RewriteCond %{HTTP_HOST} ^([^.]+)\.www\.(example\.com) [OR]
    RewriteCond %{HTTP_HOST} ^([^.]+)\.(example\.com). [OR]
    RewriteCond %{HTTP_HOST} ^([^.]+)\.(example\.com):[0-9]+
    RewriteRule (.*) http://%1.%2/$1 [R=301,L]
    #
    # If subdomain is NOT www
    RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
    # Extract (required) subdomain to %1
    RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com$
    # Rewrite if requested URL resolves to existing file or subdirectory in /<subdomain>/ path
    RewriteCond %{DOCUMENT_ROOT}/%1/$1 -f [OR]
    RewriteCond %{DOCUMENT_ROOT}/%1/$1 -d
    RewriteRule (.*) /%1/$1 [L]

    This reroutes subdomain.example.com to example.com/subdomain.
    I also make a CNAME entry in the DNS server with a wildcard host * pointing to example.com
     
  3. fatorXb2

    fatorXb2 New Member

    Hi kephra, thanks but I use NginX.

    I ended up buying a new domain, and that's funny because I was struggling 2 months to get some traffic to my subdomain website, now with the new domain there is already 50 hits/day at least in less than a week after the migration.

    I will never use subdomains again. Or maybe I will, but only if I want to hide something from Google of course..
     
  4. till

    till Super Moderator Staff Member ISPConfig Developer

    To have a new directory for a subdomain, yreate a nwe website and enter your subdomain into the domain field. As alternative you can use the vhost subdomain function in ispconfig to create the subdomain in a subdirectory of an existing domain.
     
  5. fatorXb2

    fatorXb2 New Member

    I figured this later. But the best solution was migrating everything to a new domain and redirect the old subdomain to this domain. Is great how easy was to alias that..

    Once again I do appreciate your time.
    Many thanks for ISPConfig and your hard work on this community.
     

Share This Page