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

 

Redirect from subdomain to main domain

Started by ramakant.sharma24, Feb 21, 2023, 03:02 AM

Previous topic - Next topic

ramakant.sharma24Topic starter

I need assistance with solving a problem.

Is there a way to display the user.php page with the parameter u=petro when a user types in http://petro.mysite.com, while still keeping the petro.mysite.ru domain name in their address bar? It's worth noting that there isn't an actual petro domain name.

Do you know if achieving this is possible?
  •  


SERanking

If a subdomain doesn't exist, it's impossible to redirect through .htaccess or header. However, creating a subdomain is a straightforward process. This can be done through the hosting control panel or the site where the domain was purchased.
  •  

shakilbds

Assuming DNS configuration is allowed, there are a couple of ways to handle subdomains:

- Add a wildcard entry (*.example.com) in the DNS domain settings to direct any subdomain to the main one.
- Use mod_rewrite to create a rewrite rule or parse the global variable $_SERVER['HTTP_HOST'].

DNS changes can take some time to propagate and may not work immediately. Additionally, using mod_rewrite requires some knowledge of regular expressions and can be tricky to get right. If possible, it may be worth consulting with a web developer or IT professional to ensure that any changes made are done correctly and efficiently.
  •  

daral

Yes, it is possible to achieve this using URL rewriting or redirection techniques. You can use a web server's configuration file (such as .htaccess for Apache) to rewrite the URL so that when a user types in http://petro.mysite.com, it internally redirects to http://petro.mysite.com/user.php?u=petro, but still keeps the petro.mysite.ru domain name in the address bar.

To accomplish this with Apache web server, you can use the mod_rewrite module. Here's an example of how you can configure your .htaccess file to achieve the desired behavior:

1. Open or create a .htaccess file in the root directory of your website.
2. Add the following lines to the .htaccess file:

```
RewriteEngine On
RewriteCond %{HTTP_HOST} ^petro\.mysite\.com$ [NC]
RewriteRule ^$ http://petro.mysite.ru/user.php?u=petro [L]
```

3. Save the .htaccess file.

These rules will check if the HTTP_HOST is "petro.mysite.com" and if the requested path is empty. If both conditions are met, it will redirect internally to "http://petro.mysite.ru/user.php?u=petro" without changing the domain name in the address bar.

Make sure that mod_rewrite is enabled on your Apache server, and you have appropriate permissions to modify .htaccess files. Additionally, keep in mind that the example assumes you are using Apache as your web server. If you are using a different server, the configuration process may vary.

To accomplish this with Apache web server, you can use mod_rewrite module to rewrite the URL.

First, make sure that the mod_rewrite module is enabled on your Apache server. You can check this by looking for the following line in your Apache configuration file (httpd.conf):
```
LoadModule rewrite_module modules/mod_rewrite.so
```

Once you have confirmed that mod_rewrite is enabled, you can create or modify the .htaccess file in the dоcument root directory of your petro.mysite.ru domain. If the .htaccess file doesn't exist, you can create one.

Inside the .htaccess file, you can use the following rules to rewrite the URL:
```apache
RewriteEngine On
RewriteCond %{HTTP_HOST} ^petro\.mysite\.com$ [NC]
RewriteRule ^$ http://petro.mysite.ru/user.php?u=petro [L]
```
This rule checks if the requested host is "petro.mysite.com", and if it is, it redirects them to "http://petro.mysite.ru/user.php?u=petro". The [L] flag stops any further rules from being processed.

Save the .htaccess file and test it by accessing http://petro.mysite.com. The internal redirection should happen, and the URL in the address bar should remain as petro.mysite.ru.

Note that for this to work, you need to have the necessary DNS settings in place so that the petro.mysite.com domain points to the same server as petro.mysite.ru.
  •  


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