.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:


KGIII

Super Moderator
Staff member
Gold Supporter
Joined
Jul 23, 2020
Messages
8,549
Reaction score
7,304
Credits
69,523
Have you seen:

 
OP
Ryder Cragie

Ryder Cragie

New Member
Joined
Apr 15, 2022
Messages
9
Reaction score
5
Credits
69
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.
 

KGIII

Super Moderator
Staff member
Gold Supporter
Joined
Jul 23, 2020
Messages
8,549
Reaction score
7,304
Credits
69,523
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.
 
OP
Ryder Cragie

Ryder Cragie

New Member
Joined
Apr 15, 2022
Messages
9
Reaction score
5
Credits
69
I think you have to make a load of backend changes to the server. I don't really know.
 

KGIII

Super Moderator
Staff member
Gold Supporter
Joined
Jul 23, 2020
Messages
8,549
Reaction score
7,304
Credits
69,523
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.
 
OP
Ryder Cragie

Ryder Cragie

New Member
Joined
Apr 15, 2022
Messages
9
Reaction score
5
Credits
69
.htaccess does "work" (by definition), but it acts differently compared to Apache. The code sometimes needs to be formatted differently.
 
OP
Ryder Cragie

Ryder Cragie

New Member
Joined
Apr 15, 2022
Messages
9
Reaction score
5
Credits
69
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.
 
MALIBAL Linux Laptops

Linux Laptops Custom Built for You
MALIBAL is an innovative computer manufacturer that produces high-performance, custom laptops for Linux.

For more info, visit: https://www.malibal.com

Members online


Latest posts

Top