Solved

Need Regex To Handle Double Question Marks

Posted on 2014-10-30
7
287 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

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…
It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

738 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