/    Sign up×
Community /Pin to ProfileBookmark

PHP Web.config rewrite rule

Hi, I’m aiming to output this link like: [B][url]www.mysite.com/username[/url][/B] using these codes. But the [B]user[/B] query string set its value to [B]$1[/B].

Check out this scenario and notice the username [COLOR=”#FF0000″]mark[/COLOR] became [COLOR=”#FF0000″]user?=$1[/COLOR],

[LIST]

  • [url]www.mysite.com/[/url][COLOR=”#FF0000″]mark[/COLOR] has been redirected to [url]www.mysite.com/[/url][COLOR=”#FF0000″]user?=$1[/COLOR] which was supposed to be [url]www.mysite.com/[/url][COLOR=”#FF0000″]user?=mark[/COLOR]


  • [/LIST]

    [B]The Web.config code[/B]

    [CODE]<?xml version=”1.0″ encoding=”UTF-8″?>
    <configuration>
    <connectionStrings>
    <add connectionString=”server=localhost;uid=tycoonUdyn9;pwd=&quot;?rY?%=;u5X8_&quot;;Database=tycoon” name=”tycoon” providerName=”MySql.Data.MySqlClient” />
    </connectionStrings>
    <system.webServer>
    <rewrite>
    <rules>
    <!–<rule name=”rule 1″ stopProcessing=”true”>
    <match url=”/*” ignoreCase=”true” />
    <action type=”Rewrite” url=”/capture.php?user={URL}” />
    </rule>–>
    <!– replicating matches like: http://mysite.com/username –>
    <rule name=”site” patternSyntax=”Wildcard”>
    <match url=”*” />
    <conditions>
    <add input=”{REQUEST_FILENAME}” matchType=”IsFile” negate=”true” />
    <add input=”{REQUEST_FILENAME}” matchType=”IsDirectory” negate=”true” />
    </conditions>
    <action type=”Rewrite” url=”/capture.php?user=$1″ />
    </rule>
    </rules>
    </rewrite>
    </system.webServer>
    </configuration>[/CODE]

    [B]The parser code[/B]

    [code=php]define(‘SITE_ROOT’, $_SERVER[‘DOCUMENT_ROOT’]);

    require_once(SITE_ROOT . ‘/db.php’);
    require_once(SITE_ROOT . ‘/templates.php’);

    if (isset($_GET[‘user’])) {
    if (!true_user($_GET[‘user’])) {
    header(‘Location: /broken_link.shtml’);
    } else {
    load_template(‘capture’);
    }
    }

    function true_user($user) {
    global $tubcConnection;

    $query = “SELECT * FROM users WHERE username = ?”;
    $stmt = $tubcConnection->prepare($query);
    $stmt->bind_param(‘s’, $user);
    $stmt->execute();
    $stmt->store_result();

    if ($stmt->num_rows === 1) {
    return TRUE;
    }

    return FALSE;
    }[/code]

    to post a comment
    PHP

    3 Comments(s)

    Copy linkTweet thisAlerts:
    @NogDogDec 30.2015 — WARNING: I am [i]not[/i] a Windows Server guy. Anyway, poking around the interwebs a bit, it looks to me like [i]maybe[/i] you're supposed to use [B][FONT=Courier New][COLOR="#B22222"]{R:1}[/COLOR][/FONT][/B] instead of [B][FONT=Courier New][COLOR="#B22222"]$1[/COLOR][/FONT][/B] ?
    Copy linkTweet thisAlerts:
    @tubc2015authorDec 31.2015 — But sometimes I often seen $1 which is in a wildcard instead of reference {R:1} in wordpress sites.

    What's the purpose of [COLOR="#FF0000"]$1[/COLOR]
    Copy linkTweet thisAlerts:
    @JanSmitDec 31.2015 — You can import .htaccess into IIS in the manager.
    ×

    Success!

    Help @tubc2015 spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 6.16,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @nearjob,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,
    )...