I have the following .htaccess code which does a few things, one of them being that it redirects 1.example.com to example.com/1, which works great. But I also need it to redirect 1.example.com/2 to example.com/1/2 as well, and it does do that BUT it adds a trailing slash if no path is specified on that occasion. I do not want the trailing slash. Is there any way to stop this? $1 or $ doesn't seem to ever work as it breaks everything and has to resort to ErrorDocuments. Thanks.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com [NC]
RewriteRule (.*) https://example.com/%1%{REQUEST_URI} [R=302,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com [NC]
RewriteRule (.*) https://example.com/%1%{REQUEST_URI} [R=302,L]
Last edited: