Solved

Need Regex To Handle Double Question Marks

Posted on 2014-10-30
7
278 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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.

820 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