Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7708991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:45:08+00:00 2026-06-01T00:45:08+00:00

I was wondering how I would do a complex mod_rewrite. Below is basically how

  • 0

I was wondering how I would do a complex mod_rewrite. Below is basically how I want it done.


If the user goes to:

-http://files.stuff.example.txt.r.site.com/doc.txt

Then the server would rewrite the url to:

-http://r.site.com/index.php?type=txt&username=example&dir=files.stuff&file=doc.txt


Better picture:

-http://[dir3-dir2-dir1].[username].[type].r.site.com/[file]

Rewrites to:

-http://r.site.com/index.php?type=[type]&username=[username]&dir=[dir3.dir2.dir1]&file=[file]


I created a colour coded image to clearly show what I mean:

(can’t embed images) look here:

https://i.stack.imgur.com/24H8j.png

The first subdomains are a directory structure (shown in red), so the amount of subdomains can change.

I hope someone can provide me with a solution. Either using mod_rewrite or maybe another method. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T00:45:09+00:00Added an answer on June 1, 2026 at 12:45 am

    Provided that you have configured your DNS so that requested URL hits server where your application is (maybe wildcard DNS on your domain: *.site.com -> 123.45.67.89, if supported by your DNS server/hosting), you can create more or less complicated rewrite rule. I’d do it this way:

    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} ^(.*).r.site.com$
    RewriteCond $1 !^index.php
    RewriteRule (.*) index.php?subdomain_part=%1&file_part=$1
    

    So in index.php you get $_GET['subdomain_part'] and $_GET['file_part'], which you can parse further to extract parameters according to your convention.

    Of course, you can write more complicated regex to get URL parts extracted by mod_rewrite (I’m not such an regex expert myself). However doing parsing in PHP would be much easier and you can do better error handling (e.g. if URL is not formed properly).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm wondering how i would go about making the following application: a user signs
I was wondering would I still need to use a basic game loop for
i was wondering what would be the best way to code a browser plugin
I was just wondering which would be cheaper, using a try catch block for
I am wondering how would I deal with a call to a function when
I am wondering what would be the best approach to store, for let's say
I have run a few using batch jobs, but, I am wondering what would
Am wondering if there would be any security flaw in this approach. I am
I was wondering if anyone would help with the following: I have a date
I know that snapshot isolation would fix this problem, but I'm wondering if NOLOCK

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.