Wildcard Subdomains using htacess with multiple variables

Offtopic: WOOOOOO! @dklynn in the house! Long time no see! How are you? :smiley:


Hey, I’m surviving, thank you. Okay, just barely but that’s an accomplishment these days!

How are you doing?

That was a pretty long thread but my mind kept looking for the key points mentioned above (URL and target and getting mod_rewrite to finish).



Yeah, pretty much the same :slight_smile:

My condolences, then. 'Hope things improve for you!


Thank you sir for you contribution.
We are actually trying to derive a subdomain from get method ($_GET[‘url’]) using htaccess. Also, to pass a second variable as $id to fetch product from the database.

The first code I actually wrote in the htaccess could only define variable url and left variable id as undefined.

The last code rpkamp actually gave works well by getting variable Id but variable url remains unknown.


However, this is a sample of what am trying to get.

Using 2 get variables. One for wildcard subdomain while the other for product id.

Thank you.

Hello again,

Your reference link does indeed give no URL (subdomain) but does give 2 for the id. I then used “2” (without the quotes) for the {request_uri} then “abc” both of which failed - 2 because neither was NOT matched by [aA-zZ].

REPLACE ^([aA-zZ])$ with ^([a-zA-Z]+)$ in the RewriteRule

I’d never seen the character ranges defined as aA-zZ and the original only specified (if it was a correct range) a single character.

Give that a shot and see what happens. If unsuccessful, then PLEASE provide your testing URL (with subdomain) and desired target URL (with subdomain).



Thank you.

I have replaced it.
From your reply “Your reference link does indeed give no url” , the subdomain is actually derived from a get method with a variable url using htaccess but as it stands now, even when typing the subdomain “http://gold.efficientpoint.com/test_view.php?id=2”, the value of variable url is unknown in the page. That is
instead of
<h1> The website url is (gold) </h1>

we now have

<h1> The website url is () </h1>

For the product being id, it is known and defined that’s why you see
<h2> The product is (2) </h2>

Thank you very much for your responses and help.

I have finally achieved it.
This is what am using

RewriteCond %{HTTP_HOST} ^(.*)\.efficientpoint\.com$ [NC]
RewriteRule ^(.+/)?([^/]*)$ test_view.php?url=%1&id=$2 [QSA,L,NC]

Thanks very much.


I actually used this and it worked.

RewriteCond %{HTTP_HOST} ^(.*)\.efficientpoint\.com$ [NC]
RewriteRule ^(.+/)?([^/]*)$ test_view.php?url=%1&id=$2 [QSA,L,NC]


1 Like


Please there is another issue ohhh. That rewrite rule doesnt accept two or more pages.

for example,
is being replaced by

with this htaccess:
RewriteCond %{HTTP_HOST} ^(.).efficientpoint.com$ [NC]
RewriteRule ^(.+/)?([^/]
)$ testing_view.php?url=%1&id=$2 [QSA,NC,L]
RewriteRule [1](.*)$ test_view.php?url=%1&id=$2 [QSA,NC,L]

$id= $_GET[‘id’];
$sitePostName = $_GET[‘url’];

    <h1>This is the website url (<?php echo $sitePostName; ?>)</h1>
    <h4>The product is (<?php echo $id; ?>)</h4>

$id= $_GET[‘id’];
$sitePostName = $_GET[‘url’];

    <h1>The website url is (<?php echo $sitePostName; ?>)</h1>
    <h4>The product is (<?php echo $id; ?>)</h4>

As you can see the h1 of test_view.php isn’t the same with h1 of testing_view.php
testing_view.php’s h1 is " The website url is … "
test_view.php’s h1 is “This is the website url…”

Please how will i rewrite the rule such that testing_view.php won’t overwrite test_view.php?

Best regards!

  1. ^/ ↩︎

Very simply, you look like you’re redirecting in circles and the use of ‘global’ catch-all’s isn’t helping.

The best thing I can advise is that you have a read of my ancient post (now at https://datakoncepts.com/seo) where you will learn to specify exactly what you want to match, what you don’t want to match and how to redirect.

ALSO, the Flags section will teach you that NC is not of any use in a RewriteRule (because the {REQUEST_URI} string IS case sensitive.



Seriously I have tried all I can, yet am not getting it right. Even when I remove the Last flag it still doesn’t work.

Now that I have removed the L flag and rewrite the rule for test_view.php,
test_view.php now overwrites testing_view.php

here is the code:

RewriteCond %{HTTP_HOST} ^(.*)\.efficientpoint\.com$ [NC]
RewriteRule ^(.+/)?([^/]*)$ testing_view.php?url=%1&id=$2 [QSA,NC]

RewriteRule ^([aA-zZ])$ test_view.php?url=$1
RewriteCond %{HTTP_HOST} ^(^.*)\.efficientpoint.com
RewriteRule (.*) test_view.php?url=%1

I would be so glad if you could correct me and help me get the right thing done.

SERIOUSLY, you have not read the comments above nor have you read the tutorial I referenced. Therefore, I believe that you are asking for free coding rather than taking advantage of the opportunity to actually learn (the purpose of this forum) something about being a webmaster/host. As I do not (any longer) do free coding, I must refer you to the posts above and the lengthy tutorial (with MANY examples) at my website.


Thank you very much for your effort and time. U call it free code? I had an issue with getting two get variables one as subdomain while the other as extension. After all research and brain storming, I got it right but the issue now becomes using it on two or more pages. Time will come when many developers will have this same issue and when they get to read all these comments and replies, they might get happy at first but at the end frustrated because there isn’t any solution to this problem on this forum.

Thank you very much for your time and effort once again.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.