Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Subdomain to subfolder redirect

Discussion in 'General Discussion' started by jen22, Apr 6, 2018.

  1. jen22

    jen22 Registered

    Joined:
    Apr 6, 2018
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Arizona
    cPanel Access Level:
    Reseller Owner
    Hi,
    I'm using WHM and cPanel. My intent is so use sub-domain for each separate cPanel account and then redirect (through .htaccess or other way) to my root-domain/subfolder

    example: I've created 2 cpanel accounts under WHM.
    1st account: jen.example.com (domain)
    2nd account: example.com (domain)

    both are hosted on same IP address.

    Now I want to upload files to https://jen.example.com but I want that my visitors should see the pages as https://example.com/jen

    Example: https://jen.example.com/page1.html should be shown in browser as https://example.com/jen/page1.html

    I've tried using .htaccess redirect:
    Options +FollowSymLinks
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^jen\.example\.com$
    RewriteRule ^(.*) https://example.com/jen$1 [R=301,L]

    It is redirecting, but litespeed giving a 500 error. Also I use wordpress install on jen.example.com, then it is redirected to example.com/jen but the sub-pages are not redirected.

    Is there something setting changes I should do in cPanel account(s)?
    Also Is there a need to manually create example.com/jen/ folder?

    Please guide me accordingly. my host was not able to help on this! :(
     
  2. cPanelLauren

    cPanelLauren Forums Analyst
    Staff Member

    Joined:
    Nov 14, 2017
    Messages:
    372
    Likes Received:
    20
    Trophy Points:
    93
    Location:
    Houston
    cPanel Access Level:
    DataCenter Provider
    Hi @jen22

    Is there a specific reason why you need the two to be separate accounts? I ask this only because it may be easier to achieve what you're looking to do if you created example.com -> then within the cPanel interface create the subdomain jen.example.com.

    Once that's done your folders would be created under the /home directory for the example user automatically.

    To set up jen.example.com to redirect to example.com/jen you should be able to go to cPanel>>Domains>>Redirects and set up the redirect from the UI

    Thank you,
     
  3. jen22

    jen22 Registered

    Joined:
    Apr 6, 2018
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Arizona
    cPanel Access Level:
    Reseller Owner
    The specific reason is because of inode limit per cpanel account my host has set very low. That's the reason I'm interested to host sub.domain.com(s) and redirect them virtually to domain.com/sub/
     
  4. cPanelLauren

    cPanelLauren Forums Analyst
    Staff Member

    Joined:
    Nov 14, 2017
    Messages:
    372
    Likes Received:
    20
    Trophy Points:
    93
    Location:
    Houston
    cPanel Access Level:
    DataCenter Provider
    Hi @jen22

    I understand, what you're describing should work though.

    The steps to do this would be similar to what you listed:

    1. Create example.com account (pending it didn't already exist)

    2. Create a folder in example.com's public_html called jen

    3. Create the account jen.example.com

    4. Go to cPanel>>Domains>>Redirects and add a redirect for jen.example.com -> http://example.com/jen or https://example.com/jen depending on which you'd rather use

    5. Select redirect with or without WWW if you want both to redirect

    6. Select Add

    Once this is complete the redirection should look like this in the .htaccess file for jen.example.com:

    Code:
    RewriteCond %{HTTP_HOST} ^jen\.example\.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.jen\.example\.com$
    RewriteRule ^/?$ "https\:\/\/example\.com\/jen" [R=301,L]
    in this example the domain jen.example.com or www.jen.example.com redirects to https://example.com/jen which would hold all the data for the domain.

    Thank you,
     
Loading...

Share This Page