Wildcard Subdomains using htacess with multiple variables

I have used it and am using it right now. Its still not recognizing the variable id.

Can you post your full .htaccess code please?

Ok sir

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

No wonder it doesn’t work …

Can you please replace all of that with the following?

Options -MultiViews -Indexes

RewriteEngine On

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

It almost worked. This time around variable id is defined but variable url is undefined.

You can check out the page

I guess we almost got it.

Thank you.

Sir i have actually seen something similar but i don’t really understand it. Maybe you can check it as well.

The last reply seems to show success.

Looking through this thread, I kept thinking that the %1 value is constantly being reevaluated BECAUSE mod_rewrite does not stop until there are no more matches.

The code above (from rpkamp) matches a subdomain (IF IT EXISTS) before the dot separator for the domain but requires no dot character in the {REQUEST_URI} to provide a redirection to {subdomain}.efficienthost.com/test_view.php?url={subdomain}&id={REQUEST_URI}.

I’m not sure why rp included the Options (other than good practice) nor the double ^ for the subdomain. Also, I vastly prefer designating the allowed characters in the subdomain string, including the dot separator. Making the subdomain required via the RewriteCond is correct (but the * makes all but the dot separator optional).

Question. Are you trying to rewrite to efficienthost.com? With or without www? with gold?

In other words, please give an example of the submitted URL (with subdomain) and the desired URL (after redirection) for a better answer.



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.