.htaccess Wildcard Redirect Passthrough (Web Hosting)

Ryder Cragie

New Member
Joined
Apr 15, 2022
Messages
9
Reaction score
5
Credits
69
I have hosting set up on a wildcard on my domain (*.example.com) and I would like to have the following type of redirect:

whatever-the-user-types-here.example.com > example.com/whatever-the-user-types-here

Does anyone know the code for this please? This would make my day if someone could help.

Thanks.
 
Last edited:


Have you seen:

 
I have, yes. I use LiteSpeed, not Apache. I am so bad with .htaccess that I can't even modify the code given there to see if it works.
 
LOL I too suck with .htaccess. Maybe someone'll come help that knows more than we do.
 
Wait... I was confused for a bit and decided to revisit this. Shouldn't the htaccess work just fine for LiteSpeed - as in there's no difference code needed. If memory serves, it was only in the enterprise version but I recalled it being added to the open version - and that looks like it was a few years ago, at least for mod_rewrite, which is what the snippet relies on.
 
I think you have to make a load of backend changes to the server. I don't really know.
 
I use LiteSpeed on a few accounts and .htaccess works as expected on all of them. However, on those servers I'm just a user/reseller. So, more than that I don't know other than the occasional blog posts I've encountered over the years.
 
.htaccess does "work" (by definition), but it acts differently compared to Apache. The code sometimes needs to be formatted differently.
 
Update: I've been through many pages of Google and I FINALLY found it! Here is the code:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.+)\.example\.com$ [NC]
RewriteRule ^(.*)$ https://example.com/%1 [L,R=302]

However, files are no longer accessible. So random.example.com does go to example.com/random, but the files that I am hosting are not visible. So random.example.com/test.txt does not work like it did before I added the .htaccess code. Not sure what I need to modify to get this working.
 

Members online


Latest posts

Top