homepage Welcome to WebmasterWorld Guest from 54.166.66.204
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Correcting double question marks with .htaccess
tcvdveer




msg:4626714
 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]

 

aakk9999




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

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


I don't think you want this. You should 301 redirect to the correct URL instead.

tcvdveer




msg:4626748
 3:28 pm on Nov 29, 2013 (gmt 0)

Thanks, that seems to solve it!

lucy24




msg:4626816
 9:28 pm on Nov 29, 2013 (gmt 0)

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.

g1smd




msg:4628477
 9:17 pm on Dec 6, 2013 (gmt 0)

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.
tcvdveer




msg:4628511
 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]

lucy24




msg:4628531
 2:41 am on Dec 7, 2013 (gmt 0)

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.

g1smd




msg:4628549
 7:17 am on Dec 7, 2013 (gmt 0)

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

The rule is missing the [L] flag.

tcvdveer




msg:4628580
 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]

phranque




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

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.

g1smd




msg:4628624
 2:19 pm on Dec 7, 2013 (gmt 0)

In the RegEx pattern in the Condition, the literal period needs a backslash.

lucy24




msg:4628669
 10:28 pm on Dec 7, 2013 (gmt 0)

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?

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved