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 6866665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:12:50+00:00 2026-05-27T03:12:50+00:00

I have a rewrite rule, which changes a server variable with the value of

  • 0

I have a rewrite rule, which changes a server variable with the value of a subdomain.
This works on subdomain.mydomain.nl/somethinghere but not on subdomain.mydomain.nl

<rule name="Change code" enabled="true" patternSyntax="ECMAScript" stopProcessing="false">
    <match url=".*" ignoreCase="true" />
    <conditions logicalGrouping="MatchAll" trackAllCaptures="true">
        <add input="{SERVER_NAME}" pattern="(www\.)?(\w+)\.mydomain\.nl" />
        <add input="{SERVER_NAME}" pattern="^www.mydomain.nl.*" negate="true" />
        <add input="{SERVER_NAME}" pattern="^mydomain.nl.*" negate="true" />
    </conditions>
    <serverVariables>
        <set name="MYVARIABLE" value="{C:2}" />
    </serverVariables>
    <action type="None" />
</rule>

I have tested 2 urls:
1: subdomain.mydomain.nl/somethinghere
2: subdomain.mydomain.nl

I retrieve the variable in PHP with the following code:

echo $_SERVER['MYVARIABLE'];

In case of URL 1, the output of this is “subdomain”.

In case of URL 2, the output of this is “”.

The output of URL 1 is correct, but the output of URL 2 should be “subdomain” too.

I have run a trace of both requests, and they both show that the rule is being matched and executed.

Can anyone help me?

  • 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-05-27T03:12:51+00:00Added an answer on May 27, 2026 at 3:12 am

    When you set a custom server variable, you should start it with HTTP_. When you add your own header, it should start with HTTP_X_ to add a host header starting with an X.

    To be honest, I can’t really explain why it works without HTTP_ in some scenarios, but with HTTP_ it works in all scenarios and that’s also how it’s documented.

    <rules>
        <rule name="Change code" enabled="true" patternSyntax="ECMAScript" stopProcessing="false">
            <match url=".*" ignoreCase="true" />
            <conditions logicalGrouping="MatchAll" trackAllCaptures="true">
                <add input="{SERVER_NAME}" pattern="(www\.)?(\w+)\.testsite\.nl" />
                <add input="{SERVER_NAME}" pattern="^www\.testsite\.nl$" negate="true" />
                <add input="{SERVER_NAME}" pattern="^testsite\.nl$" negate="true" />
            </conditions>
            <serverVariables>
                <set name="HTTP_X_MYVARIABLE" value="{C:2}" />
            </serverVariables>
            <action type="None" />
        </rule>
    </rules>
    

    You can now get the subdomain name with echo $_SERVER["HTTP_X_MYVARIABLE"];.

    I’ve also cleaned up your conditional regular expressions to escape the .s and also added a $ to make it truly match the exact domain names.

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

Sidebar

Related Questions

I have this rewrite rule RewriteEngine On RewriteBase /location/ RewriteRule ^(.+)/?$ index.php?franchise=$1 Which is
I have a website which has .htaccess rewrite rules. And alot of them. This
In my lighttpd config file, I have a rewrite rule like this: $HTTP[host] ==
Okay I have this RewriteRule which is supposed to redirect any request for the
I have a rewrite rule of the following form: RewriteRule ^foo/([a-zA-Z0-9]+)$ foo.php?arg=$1 [qsa,nc] It
I have a mod_rewrite rule that will send any subdomain requests to a php
I have the following rewrite rule rewrite ^/ab(.*)/(.*)$ /repo/ab$1/rtest/$2 break; When the request file
I have this rule: <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !index.php RewriteRule ^(.*)$ index.php?req=$1
I have this RewriteRule that works too well :-) RewriteRule ^([^/]*)/$ /script.html?id=$1 [L] The
I have this rule in an .htaccess file located in a directory named clips/

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.