: Redirect subdomain to folder without changing the URL I'm trying to achieve masking subdomains to folders using .htaccess UPDATE for the sake of clarity: I Would like the user to enter the url:
I'm trying to achieve masking subdomains to folders using .htaccess
UPDATE for the sake of clarity: I Would like the user to enter the url: subdomain.example.com and stay in the same url while getting the contents from example.com/subdomain
I'm using a Plesk 12 webhost.
I've tried lots of post and the only thing i could achieve was getting the redirect from xxxx.example.com to example.com/xxxx (not masked).
The thing is that the folders are generated by other program (with their own structure and content) so i don't really know how else put mod_proxy in there to make the magic happen.
UPDATED 11-06-2015 I moved the subdomain folders to /sd/ in order to have them organized and apart from any other file.
UPDATED 11-07-2015 I was able to make the program only create 1 "prettyurl" for each element, so now i don't even have folders, just /sd/template/subdomain1/, /sd/template/subdomain2 and so on.
My current .htaccess:
Options +FollowSymlinks -MultiViews
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#RewriteRules for pretty url
RewriteRule ^sd/template/index.php$ "sd/template/" [R=301,L,QSA]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule . - [L]
#sd /template/index.php
RewriteRule ^sd/template/.*?([^./]*).html$ sd/template/?pname= [L,QSA]
RewriteRule ^sd/template/([1-2]d{3})/(?:(0[1-9]|1[0-2])/(?:(0[1-9]|1[0-9]|2[0-9]|3[0-1])/)?)?$ sd/template/?d= [L,QSA]
RewriteRule ^sd/template/[^.]*?([^/.]*)/$ sd/template/?fname= [L,QSA]
RewriteRule ^sd/template/[^.]*?([^/.]*)$ "[CO]/" [R=301,L,QSA]
RewriteCond %{HTTP_HOST} ^(.*).example.com
RewriteRule ^(.*)$ /sd/template/%1 [L,NC]
</IfModule>
I created a wildcard subdomain too, but i don't really know if it helps or makes it worse.
Right now, if i enter "test1.example.com" at the adress bar i get redirected to "example.com/test1/" correctly, but what i need is to show the contents without changing the URL shown.
UPDATED 11-07-2015 Now if i use test.example.com i get redirected to test.example.com/sd/template/test/. What should i do to just get the test.example.com?
Any help is greatly appreciated as i'm stuck here after 3 days reading one and another post from all around the web.
More posts by @Pope3001725
1 Comments
Sorted by latest first Latest Oldest Best
The R flag in your RewriteRule is for forcing an external redirect. You don't want to use that if you are masking where the content is coming from.
Try this:
RewriteRule ^/(.*)$ /path/to/your/subdomain/directories/%1/ [L,NC]
You may want to be more specific in your sub domain matches to tighten up security.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.