Welcome to WebmasterWorld Guest from 54.146.59.202

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Correcting double question marks with .htaccess

     
1:09 pm on Nov 29, 2013 (gmt 0)



I am trying a way to correct a response URL with double questionmarks,

Example:
http://www.example.com/index.php?dispatch=payment?ref=123


Should become:
http://www.example.com/index.php?dispatch=payment&ref=123


Tried:
RewriteCond %{QUERY_STRING} ^dispatch=payment\?ref=(.*)$
RewriteRule ^(.*)$ $1dispatch=payment&ref=%1 [QSA]

But it displays wrong as:
http://www.example.com/index.phpdispatch=payment&ref=123

[edited by: incrediBILL at 9:53 pm (utc) on Dec 7, 2013]
[edit reason] Please use EXAMPLE.COM for all domain names [/edit]

2:18 pm on Nov 29, 2013 (gmt 0)

WebmasterWorld Administrator 5+ Year Member Top Contributors Of The Month



RewriteRule ^(.*)$ $1dispatch=payment&ref=%1 [QSA]


I don't think you want this. You should 301 redirect to the correct URL instead.
3:28 pm on Nov 29, 2013 (gmt 0)



Thanks, that seems to solve it!
9:28 pm on Nov 29, 2013 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



RewriteRule ^(.*)$ $1dispatch=payment&ref=%1 [QSA]

But it displays wrong as:
http://www.example.com/index.phpdispatch=payment&ref=123

Chorus:
It never does quite what I want
But only what I tell it


#1 The QSA flag is used only when you need to add to the existing query string while keeping any parts that were already there. Here you're trying to change or replace part of the query, so the appropriate flag is [R=301,L].

#2 The capture expressed as $1 is only the "path" of the request. To make the new stuff into a query, you have to put a ? between path and query.

The rule as written will only work if the elements of the query string always come in the same order.

There's a reason for the insistence on example.com.
9:17 pm on Dec 6, 2013 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Thanks, that seems to solve it!
Post the new code. There's plenty of scope for writing code that appears to work but still has problems.
11:21 pm on Dec 6, 2013 (gmt 0)



For applying a successful solution I adjusted the htacces to:

RewriteCond %{QUERY_STRING} ^dispatch=payment\?ref=(.*)$
RewriteRule ^(.*)$ $1dispatch=payment&ref=%1 [R=301]
2:41 am on Dec 7, 2013 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



Without a question mark in the target, AND no [L] flag?

Incidentally you don't need anchors in the (.*) pattern. By default, a Regular Expression starts as soon as it can, and continues for as long as it can. Anchors are only needed when you're looking for specific content in a specific location.
7:17 am on Dec 7, 2013 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



The rule target is missing protocol, hostname and a question mark.

The rule is missing the [L] flag.
10:50 am on Dec 7, 2013 (gmt 0)



Adjusted to (and confirmed working):

RewriteCond %{QUERY_STRING} ^dispatch=payment\?ref=(.*)$
RewriteRule ^(.*)$ $1dispatch=payment&ref=%1 [R=301,L]


The actual usage is to correct following return URL from the bank:
http://www.example.com/cscart4/index.php?dispatch=payment_notification.fail&payment=eurobnk?ref=12_reff45b176bc


to:
http://www.example.com/cscart4/index.php?dispatch=payment_notification.fail&payment=eurobnk&ref=12_reff45b176bc


Using:

RewriteEngine on
RewriteBase /cscart4
RewriteCond %{QUERY_STRING} ^dispatch=payment_notification.fail&payment=eurobnk\?ref=(.*)$
RewriteRule ^(.*)$ $1\?dispatch=payment_notification.fail&payment=eurobnk&ref=%1 [R=301,L]

[edited by: engine at 12:25 pm (utc) on Dec 7, 2013]
[edit reason] please use example.com [/edit]

1:39 pm on Dec 7, 2013 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



RewriteRule ^(.*)$ $1\?dispatch=payment_notification.fail&payment=eurobnk&ref=%1 [R=301,L]

the rule target is still missing the protocol and hostname and you don't need the backslash before the question mark.
2:19 pm on Dec 7, 2013 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



In the RegEx pattern in the Condition, the literal period needs a backslash.
10:28 pm on Dec 7, 2013 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



RewriteBase /cscart4

So the target is really
http://www.example.com/cscart4/$1?dispatch=payment_notification.fail&payment=eurobnk&ref=%1
?

Is this htaccess file located in the /cscart4/ directory?
 

Featured Threads

Hot Threads This Week

Hot Threads This Month