I want to redirect [abc].apps.example.com to the following apps.example.com/[abc] but still showing the using the [abc].apps.example.com in the url.
[abc] an be anything eg.
calendar.apps.example.com
books.apps.example.com
etc
With a bit of digging around and tweaking, I have the following setup but doesn’t work when an ending slash is missing:
RewriteEngine On
RewriteBase /
# Fix missing trailing slashes.
RewriteCond %{HTTP_HOST} !^www\.apps\.example\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.apps\.example\.com$ [NC]
RewriteCond %{DOCUMENT_ROOT}/%2%{REQUEST_URI}/ -d
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]
# Rewrite sub domains.
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} !^www\.apps\.example\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.apps\.example\.com$ [NC]
RewriteRule ^.*$ /%2/$0 [QSA,L]
When the following is entered:
calendar.apps.example.com/showcalendar/
it’s redirected correctly to: apps.example.com/calendar/showcalendar/
But for when a trailing slash is missing
calendar.apps.example.com/showcalendar
I get a 404 error saying /calendar/calendar/showcalendar/ not found.
Please, if you know what’s wrong with the above code or have a better solution do let me know.
Cheers,
Doggy
try the following rewrite rule for adding trailing slashes.