{"id":468,"date":"2022-01-14T13:05:33","date_gmt":"2022-01-14T13:05:33","guid":{"rendered":"https:\/\/docs.osclasspoint.com\/?p=468"},"modified":"2023-01-02T20:38:36","modified_gmt":"2023-01-02T20:38:36","slug":"subdomains-configuration","status":"publish","type":"post","link":"https:\/\/docs.osclasspoint.com\/subdomains-configuration","title":{"rendered":"Subdomains configuration"},"content":{"rendered":"\n<p>Osclass has very powerful feature that allows you to setup subdomains based on your data (dynamical subdomains).<\/p>\n\n\n\n<p><strong>Subdomain types:<\/strong><\/p>\n\n\n\n<ul><li>User based subdomains<\/li><li>Category based subdomains<\/li><li>Location based subdomains. This includes country, region and city<\/li><\/ul>\n\n\n\n<h2>Updates in Osclass<\/h2>\n\n\n\n<ul><li>Go to your file system or FTP open config.php located in root folder of your osclass installation<\/li><li>Change:<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">define('WEB_PATH', 'https:\/\/yourdomain.com\/');<\/pre>\n\n\n\n<p>Into:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">define('WEB_PATH', 'https:\/\/' . $_SERVER['HTTP_HOST'] . '\/');\ndefine('COOKIE_DOMAIN', 'domain.com');<\/pre>\n\n\n\n<p>Note that we&#8217;ve also defined COOKIE_DOMAIN that will help to transfer cookies accross domain and subdomains. So for example if you login as admin in domain.com, you will be logged-in as admin in *.domain.com as well. Same is valid for users and other Osclass cookies &amp; session data.<\/p>\n\n\n\n<p>No other settings are needed for cookies &amp; sessions, as this affect both of them.<\/p>\n\n\n\n<ul id=\"block-1a86f92d-16ad-41ba-b42e-aadfa9176d53\"><li>Save updates made in config.php<\/li><li>Log in to your Oc-admin<\/li><li>Go to <strong>Settings &gt; Advanced<\/strong><\/li><li>Select your subdomain type in the select box and press <strong>&#8220;Save changes&#8221;<\/strong> button<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1024\" height=\"610\" src=\"https:\/\/docs.osclasspoint.com\/wp-content\/uploads\/2022\/12\/image-1024x610.png\" alt=\"Classifieds subdomain configuration for Osclass\" class=\"wp-image-574\" srcset=\"https:\/\/docs.osclasspoint.com\/wp-content\/uploads\/2022\/12\/image-1024x610.png 1024w, https:\/\/docs.osclasspoint.com\/wp-content\/uploads\/2022\/12\/image-300x179.png 300w, https:\/\/docs.osclasspoint.com\/wp-content\/uploads\/2022\/12\/image-768x458.png 768w, https:\/\/docs.osclasspoint.com\/wp-content\/uploads\/2022\/12\/image-60x36.png 60w, https:\/\/docs.osclasspoint.com\/wp-content\/uploads\/2022\/12\/image-150x89.png 150w, https:\/\/docs.osclasspoint.com\/wp-content\/uploads\/2022\/12\/image.png 1421w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Your Osclass is now ready for subdomains. It will still work as usual on base domain.<\/p>\n\n\n\n<p>Now continue to required updates on hosting side to make subdomain URLs work and show content from base domain.<\/p>\n\n\n\n<h2>Updates on hosting<\/h2>\n\n\n\n<ul><li>Log in to your hosting backoffice or control panel (cPanel)<\/li><li>Go to the subdomains section and create new subdomain<\/li><li>Enter star sign (*) as subdomain name<\/li><li>Alternatively, you may create masked redirect of *.domain.com to domain.com &#8211; masked means that you stay on *.domain.com, but content is loaded from domain.com<\/li><\/ul>\n\n\n\n<p>Some hosting companies may require to create &#8220;A&#8221; record in DNS that will point out to domain.com IP address or configuration of Apache.<\/p>\n\n\n\n<p>Let&#8217;s check it out step by step.<\/p>\n\n\n\n<h3>DNS Wildcard<\/h3>\n\n\n\n<p>First, you must identify to which IP resolve any of your subdomains.<br>So, country1.domain.com will resolve the same IP as country2.domain.com and all these will be same as IP of domain.com.<\/p>\n\n\n\n<p>In the examples we will use as your IP server <span style=\"text-decoration: underline;\">127.0.0.1<\/span> and as a domain <span style=\"text-decoration: underline;\">domain.com<\/span>.<br>You should replace this values for your IP and domain.<br>These may vary based on DNS Manager.<br>We will create &#8220;A&#8221; record for DNS.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Bind<br>*.domain.com. A 127.0.0.1<\/pre>\n\n\n\n<p>Finally, if you have another subdomain pointing to another IP, you should just specify it before the wildcard (*).<br>As example you may not want to resolve mail.domain.com to same IP as your domain.com.<\/p>\n\n\n\n<p>Once done, it can take up to 24 hours until new DNS records take effect (depends on hosting, mostly within several minutes).<\/p>\n\n\n\n<h3>Apache Wildcard<\/h3>\n\n\n\n<p>Each hosting service can be specific, here we will explain VirtualHost configuration.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;VirtualHost *:80&gt;\n  ServerName domain.com\n  ServerAlias *.domain.com\n\n  CustomLog \/var\/log\/apache2\/domain.com_access_log combined\n  ErrorLog \/var\/log\/apache2\/domain.com_error_log\n  \n  &lt;Directory \/var\/www\/domain.com\/web&gt;\n    Options -Indexes FollowSymLinks -MultiViews\n    AllowOverride All\n    Order allow,deny\n    allow from all\n  &lt;\/Directory&gt;\n&lt;\/VirtualHost&gt;<\/pre>\n\n\n\n<p>This configuration says that any call that comes to any subdomain of domain.com will go to the Osclass installation folder (*.domain.com >>> domain.com).<\/p>\n\n\n\n<h3>Alternative #1<\/h3>\n\n\n\n<p>On some hostings, like hostgator, it is required just to create wildcard subdomain and point it to \/public_html folder (share document root).<\/p>\n\n\n\n<h3>Alternative #2<\/h3>\n\n\n\n<p>If all above steps has failed, simply copy content from Osclass installation directory (public_html) and copy whole content to wildcard subdomain folder. Note this may not be handy as you need to keep all files in sync with based folder and do updates in config.php in base folder + subdomain folder.<\/p>\n\n\n\n<h2>SSL \/ https setup<\/h2>\n\n\n\n<p>Once you have your subdomains setup, make sure you use https and correct SSL certificate. <\/p>\n\n\n\n<p>Usually, only what you need to make sure is that your current SSL certificate covers all subdomains (*.domain.com), but in some cases, this may not be enough.<\/p>\n\n\n\n<p>Example is, when you run subdomain on your.domain.com and subdomains are *.your.domain.com, in that case i.e. Let&#8217;s encrypt certificate may not cover subdomains and can report errors.<\/p>\n\n\n\n<p>This can be fixed! &#8230; but only for those subdomains where you know all entries and it&#8217;s less than 100 of them (country\/region subdomains, but optionally also city subdomains, if you have just few cities).<\/p>\n\n\n\n<p>Solution is to create certificate for each subdomain specifically, not using wild card:<\/p>\n\n\n\n<ul><li>sub1.your.domain.com<\/li><li>sub2.your.domain.com<\/li><li>sub3.your.domain.com<\/li><li>etc&#8230;<\/li><\/ul>\n\n\n\n<p>This will avoid using wild cards and secure your subdomains with valid SSL. In case you need wildcard on this level, you may need to look for paid SSL certificate that can handle not just *.domain.com wildcard, but also *.*.domain.com wildcard.<\/p>\n\n\n\n<p>Now you have subdomain based classifieds!<\/p>\n\n\n\n<h2>Data used in subdomains and subdomain generated parameters<\/h2>\n\n\n\n<p>You may wonder what kind of data are used to create subdomain URL, especially what is replaced by &#8220;*&#8221;<\/p>\n\n\n\n<ul><li><strong>User<\/strong>&#8211; username field from user profile (it&#8217;s like slug!). That is also reason why username must be unique. Example: johndoe.domain.com. <br>Parameter <span style=\"text-decoration: underline;\">sUser<\/span> will contain user ID.<\/li><li><strong>Category<\/strong>&#8211; category slug, must be unique. Example: cars.domain.com, for-sale.domain.com.<br>Parameter <span style=\"text-decoration: underline;\">sCategory<\/span> will contain category ID.<\/li><li><strong>Country<\/strong> &#8211; country slug. Example: united-states.domain.com. You might want to change country slug to have it like us.domain.com, de.domain.com etc using country code instead.<br>Parameter <span style=\"text-decoration: underline;\">sCountry<\/span> will contain country code.<\/li><li><strong>Region<\/strong>&#8211; region slug. Example: alabama.domain.com<br>Parameter <span style=\"text-decoration: underline;\">sRegion<\/span> will contain region ID.<\/li><li><strong>City<\/strong>&#8211; city slug. Example: los-angeles.domain.com<br>Parameter <span style=\"text-decoration: underline;\">sCity<\/span> will contain city ID.<\/li><\/ul>\n\n\n\n<p>In case you access subdomain to that does not exists entry in database, Osclass returns 404 page.<\/p>\n\n\n\n<p>You may get parameter value also by calling osc_subdomain_id() that contains ID of current subdomain (empty on top-domain).<\/p>\n\n\n\n<p>Slugs for locations can be configured in <strong>&#8220;Backoffice &gt; International &gt; Locations&#8221;<\/strong>, for categories in <strong>&#8220;Backoffice &gt; Settings &gt; Categories&#8221;<\/strong> and for users in <strong>&#8220;Backoffice &gt; Users &gt; Edit user&#8221;<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Osclass has very powerful feature that allows you to setup subdomains based on your data (dynamical subdomains). Subdomain types: User based subdomains Category based subdomains Location based subdomains. This includes country, region and city Updates in Osclass Go to your file system or FTP open config.php located in root folder of your osclass installation Change: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[15,12],"tags":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/docs.osclasspoint.com\/wp-json\/wp\/v2\/posts\/468"}],"collection":[{"href":"https:\/\/docs.osclasspoint.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.osclasspoint.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.osclasspoint.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.osclasspoint.com\/wp-json\/wp\/v2\/comments?post=468"}],"version-history":[{"count":9,"href":"https:\/\/docs.osclasspoint.com\/wp-json\/wp\/v2\/posts\/468\/revisions"}],"predecessor-version":[{"id":583,"href":"https:\/\/docs.osclasspoint.com\/wp-json\/wp\/v2\/posts\/468\/revisions\/583"}],"wp:attachment":[{"href":"https:\/\/docs.osclasspoint.com\/wp-json\/wp\/v2\/media?parent=468"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.osclasspoint.com\/wp-json\/wp\/v2\/categories?post=468"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.osclasspoint.com\/wp-json\/wp\/v2\/tags?post=468"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}