Solved

Need Regex To Handle Double Question Marks

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

Suggested Solutions

Title # Comments Views Activity
Weird Samba Connectivity Issue... 7 39
ignore other .htaccess 2 43
What is linux 4.8.22? Is it the same as ubuntu 16.10 ?? 2 36
linux 13 41
Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
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.

815 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

12 Experts available now in Live!

Get 1:1 Help Now