.htaccess - subdomain redirection to folder

This question may have been asked more than a thousand times, but I tried so many scripts and searched for so long that I couldn’t find anything, I thought, let me just ask.

I just want m.daltonempire.nl to m.daltonempire.nl redirected to daltonempire.nl/m/ without seeing the URL change.

Therefore, if m.daltonempire.nl/hello.php requested, I want the user to continue to see this URL, while the specified page is actually daltonempire.nl/m/hello.php .

Note: I do not want www. so just http://m.daltonempire.nl

Thanks in advance,

Isaiah vs Hunen

+5
redirect php apache subdomain .htaccess
Oct 29 '13 at 16:22
source share
3 answers

I set the CNAME of my subdomain below:

blog.mydomain.com

to my wordpress installed in the /blog/ folder under the root directory.

Previously, I needed to use this url to call wordpress:

http://blog.mydomain.com/blog/

what is ugly. I tried a lot of redirect code:

http://blog.mydomain.com/

to a folder so that I can use it as my wordpress url.

Finally, I got a .htaccess setting that works:

  RewriteEngine On RewriteCond %{HTTP_HOST} ^blog\.mydomain\.com$ RewriteCond %{REQUEST_URI} !^/blog/ RewriteRule (.*) /blog/$1 

I have another CNAME subdomain: http://forum.mydomain.com to install mybb in the /forum/mybb/ folder, so .htaccess needs to be placed [L] in each of the RewriteRule code, as shown below.

  RewriteEngine On RewriteCond %{HTTP_HOST} ^forum\.tophyips\.info$ RewriteCond %{REQUEST_URI} !^/forum/mybb/ RewriteRule (.*) /forum/mybb/$1 [L] RewriteCond %{HTTP_HOST} ^blog\.tophyips\.info$ RewriteCond %{REQUEST_URI} !^/blog/ RewriteRule (.*) /blog/$1 [L] 

If you want to use the code, please remember to include the URL address of the URL and the cookie in the application configuration file, following the setting to ensure the correct redirection.

+2
Mar 31 '15 at 8:11
source share

Try this example:

 RewriteCond %{HTTP_HOST} ^([^/.]+)\.example\.com$ RewriteCond %1 !^(www|ftp|mail)$ [NC] RewriteRule (.+)$ "http://example.com/%1" [L,P] 

Any requests from http://test.example.com will be displayed at http://example.com/test/...

Try a googling dynamic subdomain with php and htaccess to get the best search results.

+4
Oct 29 '13 at 16:27
source share

Add this to your .htaccess in your web 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 will allow you to access /exists.php and not rewrite it to /m/exists.php . Delete these two if you want to overwrite, even if it could potentially override existing files and directories.

+4
Oct 29 '13 at 16:27
source share



All Articles