This question has probably been asked for over a thousand times, but I've tried so many scripts, and googled so long while finding nothing, I thought, let's just ask.
I simply want m.daltonempire.nl
to be redirected to daltonempire.nl/m/
without the user seeing the URL change.
So if m.daltonempire.nl/hello.php
is requested, I want the user to keep seeing this URL, while the page given is actually daltonempire.nl/m/hello.php
.
Note: I do not want www.
, so simply http://m.daltonempire.nl
Thanks in advance,
Isaiah v. Hunen
Enter the URL of the Directory to redirect from a Subdomain Add in the field the full URL of the directory (for example: https://www.aleydasolis.com/blog/) where you want to redirect from a subdomain (for example: http://blog.aleydasolis.com/).
Under Modify a Subdomain, locate the domain you want to redirect, then click its Manage Redirection link on the right. In the text box, type the URL you would like visitors to be redirected to if they go to the subdomain sample1.hgexample.com. Click Save. You will see the redirected URL under the Redirection column.
Sometimes you may need to redirect to subfolder when you move your website's root folder contents to a new subdirectory. You can easily redirect to subdirectory using . htaccess file in Apache web server.
Add this to your .htaccess
in your web root /
directory
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^m\.daltonempire\.nl$ [NC]
RewriteCond %{REQUEST_URI} !^/m(/|$) [NC]
RewriteCond %{REQUEST_FILENAME} !-d # not a dir
RewriteCond %{REQUEST_FILENAME} !-f # not a file
RewriteRule ^(.*)$ m/$1 [L]
The %{REQUEST_FILENAME}
conditions would let you access /exists.php
and not rewrite it to /m/exists.php
. Remove those two if you want to rewrite even if that may potentially override existing files and directories.
Try this example:
RewriteCond %{HTTP_HOST} ^([^/.]+)\.example\.com$
RewriteCond %1 !^(www|ftp|mail)$ [NC]
RewriteRule (.+)$ "http://example.com/%1" [L,P]
Any requests http://test.example.com
will be mapped to http://example.com/test/...
Try googling dynamic subdomain with php and htaccess
to get better search results.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With