Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Apache RewriteRule or RewriteCond

Status
Not open for further replies.

johngiggs

Technical User
Oct 30, 2002
492
US
Hi,

I've been trying to craft a RewriteRule to alleviate an issue we're seeing with some inbound links. Something is appending ?null to the URL.

I tried several RewriteCond and RewriteRule options I could think of to no avail. A sample URL is:

Code:
[URL unfurl="true"]http://www.mysite.com/myAction.action[/URL][b];[/b]id=714&showAllSites=true[b]?null[/b]
which should instead be:

Code:
[URL unfurl="true"]http://www.mysite.com/myAction.action?id=714&showAllSites=true[/URL]

So essentially a ? should be put in place of the ; and the ?null should be stripped off.

Any help would be greatly appreciated.

Thanks,

John
 
Please edit the post and 'break' the auto linking so we can see the URI.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.

Never mind this jesus character, stars had to die for me to live.
 
Hi

This works for me :
Code:
[b]RewriteRule[/b] [green][i]"(.+);(.*)"[/i][/green] [green][i]"$1?$2"[/i][/green]

Feherke.
feherke.ga
 
Hi Feherke,

Thank you for the tip. I had no such luck with the RewriteRule running Apache 2.2.15.

Also, I don't think the rule you mentioned would also strip off any trailing ?null string, but I suspect that could be a 3rd variable you add to the string.

Any other suggestions?

Thanks,

John
 
Hi

John said:
Also, I don't think the rule you mentioned would also strip off any trailing ?null string
Not explicitly, but due to the rule's effect it disappears.

But now that you emphasized on this, maybe should had asked before : what exactly you want ? The rule I wrote it performs mod_rewrite's default action : rewrites. Do you want it redirected instead ?

John said:
Any other suggestions?
Try again.

I use Apache 2.4.18, my [tt]DOCUMENT_ROOT[/tt] is /var/ and for that directory [tt]AllowOverride[/tt] includes [tt]FileInfo[/tt]. Then I wrote :
Code:
[b]RewriteEngine[/b] on
[b]RewriteBase[/b] [green][i]"/"[/i][/green]
[b]RewriteRule[/b] [green][i]"(.+);(.*)"[/i][/green] [green][i]"$1?$2"[/i][/green] [R]
( Note : [tt]RewriteBase[/tt] needed only because I put the rule in .htaccess; [tt][R][/tt] added to redirect instead of rewrite. )
Code:
[teal]<?php[/teal]
[COLOR=orange]print_r[/color][teal]([[/teal]
    [i][green]'$_SERVER'[/green][/i] [teal]=>[/teal] [COLOR=orange]array_intersect_key[/color][teal]([/teal][navy]$_SERVER[/navy][teal],[/teal] [COLOR=orange]array_flip[/color][teal]([[/teal][i][green]'REQUEST_URI'[/green][/i][teal],[/teal] [i][green]'SCRIPT_NAME'[/green][/i][teal]])),[/teal]
    [i][green]'$_GET'[/green][/i] [teal]=>[/teal] [navy]$_GET[/navy][teal],[/teal]
[teal]]);[/teal]
( Note : I use PHP here, but that should make no difference. )

In the browser's location bar I type [navy][ignore][/ignore][/navy]

The browser redirects to [navy][ignore][/ignore][/navy] and displays :
Code:
Array
(
    [$_SERVER] => Array
        (
            [REQUEST_URI] => /myAction.php?id=714&showAllSites=true
            [SCRIPT_NAME] => /myAction.php
        )

    [$_GET] => Array
        (
            [id] => 714
            [showAllSites] => true
        )

)
While in the log it writes :
Code:
127.0.0.1 - - [10/Jan/2017:09:03:02 +0000] "GET /myAction.php;id=714&showAllSites=true?null HTTP/1.1" 302 596
127.0.0.1 - - [10/Jan/2017:09:03:02 +0000] "GET /myAction.php?id=714&showAllSites=true HTTP/1.1" 200 412

Feherke.
feherke.ga
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top