Solved

Need Regex To Handle Double Question Marks

Posted on 2014-10-30
7
266 Views
Last Modified: 2014-11-11
I have several 404 links that need to be redirected.  They are from an external source so I don't have the control to change the links.  So I am wanting a rewrite rule for htaccess I can use.

Here is a sample of the original link:  http://www.abc.com/index.php?controller=product?pageid=444

Here is what it should look like:  http://www.abc.com/index.php?controller=product&id_product=444

This is the rewrite I am trying but it doesn't match.  Neither does the other option which escapes the ? in the rewrite rule.

RewriteCond %{QUERY_STRING} ^controller=product?pageid=444$ [NC]
RewriteRule ^/index\.php$ /index.php?controller=product&id_product=444? [R=301,L]

RewriteCond %{QUERY_STRING} ^controller=product?pageid=444$ [NC]
RewriteRule ^/index\.php$ /index.php\?controller=product&id_product=444? [R=301,L]

Please tell me what I am doing wrong in the regexes I have.

Thanks,
0
Comment
Question by:sharingsunshine
7 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 40413643
Did you try escaping the ? in RewriteCond?
0
 

Author Comment

by:sharingsunshine
ID: 40413700
I just now tried it but there was no change.  So I then escaped the ? in the rewrite rule and that made no difference either.
0
 
LVL 26

Assisted Solution

by:wilcoxon
wilcoxon earned 500 total points
ID: 40417791
Are you sure the variable contains controller=product?pageid=444 and not just pageid=444?  That would be my first thought.

How did you try escaping question mark?  Did you try replacing it with %3F?  That would be my second thought.

I'm not familiar with htaccess regex redirects so this may be a dumb question.  Have you tried removing the ^ from the beginning of the regex (which would only fix it is the var contains the full URL and not the portion after the question mark)?
0
 
LVL 15

Expert Comment

by:Insoftservice
ID: 40418090
I hope you want to redirect 404 pages only.

RewriteEngine on
ErrorDocument 404 /index.php
0
 

Accepted Solution

by:
sharingsunshine earned 0 total points
ID: 40421869
I found another source and this is what they gave me which works.

RewriteCond %{QUERY_STRING} controller=product
RewriteCond %{QUERY_STRING} pageid=([0-9]*)$
RewriteRule ^(.*)$ /index.php?controller=product&id_product=%1 [R=301,L]

No, these are actual product pages.  Hence, why I have the two parameters that I want to redirect to.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now