Subdomains, 403 errors, and you. Or me at least

Good day,

I’m trying to set up subdomains for my website and I’ve never done it before and cannot find easy instructions for it. I am not using the modx cloud, I am set up on godaddy, and have had some success but not enough. I’m asking for in two ways, either a tutorial on how to set up modx subdomains, or figuring out why I am receiving a 403 error.

The 403 error I suspect is either because htaccess is set up wrong or I don’t have files set up under the subdomain folder which… I can’t imagine why I would do that.

Any help is appreciated, thank you

I’m trying to set up subdomains for my website

I’m not sure what you mean by that. You can put your site in a subdomain, but web sites are usually in a particular domain or a single subdomain, not multiples. Even if you’re trying to direct more than one URL to reach the same site, the site would be in a single domain or sub-domain.

If you’re trying to set up multiple subdomains on your server, that’s not really a MODX question – it’s a hosting question.

Can you be more specific about what you’re trying to do?

Sure thing, thank you for responding.

I’ve used a previous service where there would be different subdomains depending on the user

for example:

garyatwell.companyname.com
cindytorres.companyname.com
patrickstar.companyname.com

The idea is to have one set of code written and when I update it, it would update everyones code all at once. I am a jr developer who was set loose into the wild world and may not properly understand subdomains. Thank you for any help

Actually creating the subdomains is done at the DNS level. I think GoDaddy uses cPanel so, if you can figure out how to get to cPanel, the tools in the “Domains” section of the dashboard will let you do what you need.

If you already have the subdomains set up and you want MODX to serve content on both companyname.com and whoever.companyname.com then you’ll need to install the ContextRouter extra. After that you can create contexts for each subdomain, create the necessary settings for them, and then reuse whatever code you need across any of the contexts. I can go into more detail if this is, in fact, what you’re after.

1 Like

If I’m understanding you, you could point all of those subdomains at your home page using either your hosts tools (e.g. cPanel) if the host allows it. Or redirect them all to the appropriate page with rewrite rules in the
.htaccess file in the MODX root.

Off the top of my head, I think this would work in the MODX .htaccess file you add this just below the Rewrite Base and Rewrite Engine on lines:

RewriteEngine On
RewriteBase /  (or whatever)

RewriteCond %{HTTP_HOST} ^garyatwell\.companyname\.com$ [NC]
RewriteCond %{HTTP_HOST} ^cindytorres\.companyname\.com$ [NC]
RewriteCond %{HTTP_HOST} ^patrickstar\.companyname\.com$ [NC]
# etc.

RewriteRule ^(.*)$ https://companyname.com%{REQUEST_URI} [R=301,NC,L,QSA]

This version, if it works, would keep you from having to add all the names individually:

RewriteEngine On
RewriteBase /  (or whatever)
RewriteCond %{HTTP_HOST} ^.+\.companyname\.com$ [NC]
RewriteRule (.*) http://companyname.com/%{REQUEST_URI} [L,R=301,QSA]
1 Like

Thank you so much @dev_willis and @bobray,

I’m going to do my best with your suggestions and shared knowledge. GoDaddy does use cPanel and I have set it up but my understanding of how subdomains work was much lower than I thought.

I’m going to follow up on your advice and let you know how it turns out

I’m wondering if you could explain a little more about what your desired end result is. You might be making your life more difficult than it needs to be?!

Would garyatwell.domain.com and cindytorres.domain.com be fully fledged websites with their own set of pages and content. Would they share a style with www.domain.com?

Or do you just require content areas for those individuals?

If so is it worth considering having only the main domain and host their content on pages within it on: www.domain.com/garyatwell
www.domain.com/cindytorres

Would Gary and Cindy expect to have their own login to a manager area and create their own pages and content, or could they just populate required information for their profile page by filling in a form?

Excellent question! They would both be the same websites, except in the back end users would be able to edit their own content, which truthfully would be just a <ul> and <a>. They could add and remove items.

The URL is very highly preferred to stay with the users names first as these users are doing promotional stuff like realty and sales, so they they will definitely want their name first

So each user has their own personalized version of the same site? Or are all the sites identical and each user is responsible for some portion of the content? If the former, I think ContextRouter is the way to go. If the latter, just pointing all the subdomains to the same place should be enough.

1 Like

Ok, just wanted to give an update. I’ve made some headway on this and am updating this for others who may end up in a similar situation. This is still in development, and I will add more detail later as I get closer to finishing. I’m getting assistance from one of my favorite developers on this. Seems I am close, but this stuff is tough for me. Since the post included 403 error, I guess I should give the short fix here: My subdomain root folder was not loading anything because it was not loading files from the websites root files. theres nothing at public_html/garyatwell.example.com, so make it point to public_html/ instead

First of all, I need to create a new context and name it after the employee.

I need to go into the cpanel (if using godaddy, yourwebsite.com/cpanel) and create a subdomain, and make sure the root folder is not a new root folder like it will likely want to do. Example: garyatwell.example.com will have a root folder of public_html/garyatwell.example.com, change it remove everything after public_html)

Go to your domain manager and make sure to create a new A record under the DNS and make sure that it points to the website IP (open command prompt, type in ‘ping yourwebsite.com’)

She has created user contexts and groups so that way adding/removing people and permissions will be a snap. Also, since we created that context earlier, users will be able to log in at garyatwell.example.com/manager and only be able to see their own files, stay out of the website root files, and be able to handle their own back end. Make sure your security settings are good and be sure to dogfood yourself on this so you can make sure you didn’t overlook anything and leave your site vulnerable.

Another issue I had was setting up MIGX properly. Below are my personal notes I created and they should be easy to follow.

You’ll need to go to Elements and create a new Template Variable. Always name them with MIGX- in front. Add in a caption that tells the user what type of migx this is (call to action, for example.)Then, click on Input options, and from there, past the code below in the appropriate box. Do not make it static. Choose input type migx

Form tabs code - this one is what you see in the back end of modx and is when you’re actually creating things you’ll be calling later. This is for the pop up window in the back end.
[{“caption”:“Call to Action”, “fields”: [
{“field”:“ctaTitle”,“caption”:“Title”},
{“field”:“ctaDesc”,“caption”:“Description”,“inputTVtype”:“textarea”},
{“field”:“ctaButton”,“caption”:“Button Text”},
*{“field”:“ctaLink”,“caption”:“URL”} *
]
}]

to use these, use [[+ctaTitle]] in the [[getImagesList?]] below

Grid Columns - goes into the back end and is what you see in the back end of modx when you are entering content on the page. You’re kind of building the back end menu this way. This is for the back end where you are on the page and its showing you things at a glance.
[{“header”: “Title”, “height”: “50”, “sortable”: “true”, “dataIndex”: “ctaTitle”},
{“header”: “Description”, “height”: “50”, “sortable”: “true”, “dataIndex”: “ctaDesc”},
{“header”: “Button Text”, “height”: “50”, “sortable”: “true”, “dataIndex”: “ctaButton”},
{“header”: “URL”, “height”: “50”, “sortable”: “true”, “dataIndex”: “ctaLink”}
]

below is code that shows how to change the tv type to allow images. Note the “inputTVtype”:
{“field”:“employee-image”,“caption”:“Image”,“inputTVtype”:“image”} -

on the MIGX under the Input Options tab, the top one goes in “Form Tabs” and the bottom one goes in “Grid Columns”
set it to show on your Home template and voila, you have a migx table for the CTAs
on the MIGX TV *

thgen go to template access, give access to the template you want to apply this to, then name things in General information tab

Adjust this code to match the things you have named.

This goes in the template
[[getImageList?
&tvname=insert tv name you saved as above - MIGX-***
&tpl=@CODE:<li>[[+idx]]<h1>[[+title]]</h1><p>[[+ctaDesc]]</p></li> ]]