If you like DNray Forum, you can support it by - BTC: bc1qppjcl3c2cyjazy6lepmrv3fh6ke9mxs7zpfky0 , TRC20 and more...

 

How can a third-level domain be created using .htaccess?

Started by kumarajite, Apr 26, 2023, 08:07 AM

Previous topic - Next topic

kumarajiteTopic starter

On host-ed.net, there is a website with a level 2 hosting that requires the addition of approximately 30 third-level domains. However, the hosting only allows one subdomain of the third level.

The solution was to implement it via .htaccess using the code provided . A region folder was created in the public_html folder with an index.html file, but clicking on the link for region.site.ru resulted in an error. Seeking guidance on how to properly implement the solution.

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.site\.com$
RewriteCond %{HTTP_HOST} (www\.)?(.*)\.site\.com$
RewriteCond %{REQUEST_URI} !public_html/
RewriteRule ^(.*)$ public_html/%2/$1
  •  


mickyrobert

Your provider needs to configure a wildcard for a third-level domain, and simply using .htaccess will not suffice.
However, it seems that the provider is reluctant to make this configuration.
  •  

marissadsilva

If a user requests an address domain1.site.com that does not exist, they will receive an error message and nothing will reach your web server.
To resolve this, configuration should be done on a dns server rather than Apache.
  •  

searchcandy

Assuming that there are some great pages on remote servers and we wish to incorporate them into our website, we have various options. We may use a mirror program for FTP servers which manages updates of copied data on the local device.

Alternatively, we could use a webcopy program that works similarly over HTTP. However, both of these technologies have a significant drawback - the local copy is always up-to-date as often as we run this program. Ideally, the mirror should be dynamic with a complete correspondence of copies, irrespective of the frequency of running the program.

Therefore, we require an automatic data update feature for updating data on a remote server. To accomplish this, we can deploy the Proxy Throughput option (flag [P]) so that we can display a remote page or even a fully deleted site into our web space.

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^mysite.com
RewriteRule (.*) http://www.mysite.com/$1 [L,R=301]

RewriteCond %{HTTP_HOST} ^([^\.]+)\.mysite\.com$ [NC]
RewriteCond %{HTTP_HOST} !^www\.mysite\.com(.*)$ [NC]
RewriteRule ^(.*)$ index.php?domainname=%1%2 [L,QSA]
  •  

vnit969

I will provide a thorough explanation of how to set up multiple third-level domains using .htaccess without using any formatting marks.

To start, create a directory structure within your public_html folder. Each third-level domain should have its own folder containing an index.html file. For example, if you want to set up region.site.com, create a folder named region within public_html. The complete path will therefore be public_html/region/index.html.

Next, you will need to create or edit the .htaccess file in the public_html folder. The purpose of this file is to enable and manage URL rewriting for your third-level domains. Here is what the code should include:

- First, enable the rewrite engine with the line RewriteEngine On.
- Set the base URL for all rules with RewriteBase /.
- To check for third-level domains, use the condition RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.site\.com$ [NC]. This line captures the subdomain, such as region, into a variable.
- The next condition is to prevent rewriting already handled URIs with the line RewriteCond %{REQUEST_URI} !^/public_html/ [NC].
- Finally, include the rule that rewrites the URL so it points to the appropriate folder using RewriteRule ^(.*)$ public_html/%2/$1 [L].

The full .htaccess code should look like this:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.site\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/public_html/ [NC]
RewriteRule ^(.*)$ public_html/%2/$1 [L]

Make sure to save this file after adding the code.

After setting up your .htaccess file, you must ensure that your DNS records are configured correctly. For each third-level domain like region.site.com, create an A record that points to your server's IP address. This process typically involves accessing the DNS management section of your domain registrar and adding a new A record for every subdomain.

Once you have completed these steps, test the setup by entering region.site.com in your web browser. If everything is configured correctly, the site should display the content of the index.html file located in public_html/region/.

If you encounter an error, it is essential to check your server's configuration. Ensure that the mod_rewrite module is enabled in your Apache server and that the AllowOverride directive is correctly set to allow the use of .htaccess files. An example configuration might look like this:

<Directory /path/to/your/public_html>
AllowOverride All
</Directory>

This line must be placed correctly in your Apache configuration file.

For troubleshooting purposes, examine your server's error logs. You can typically find these logs in your hosting control panel or directly on your server. They provide insights into potential issues, such as permission errors or incorrect paths.

Consider implementing a fallback error page if visitors navigate to a subdomain that doesn't exist. A simple 404.html file at the root of your site can guide users back to your main domain or provide navigation options.
  •  


If you like DNray forum, you can support it by - BTC: bc1qppjcl3c2cyjazy6lepmrv3fh6ke9mxs7zpfky0 , TRC20 and more...