Solved

Need Regex To Handle Double Question Marks

Posted on 2014-10-30
7
261 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
Comment Utility
Did you try escaping the ? in RewriteCond?
0
 

Author Comment

by:sharingsunshine
Comment Utility
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
Comment Utility
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
Comment Utility
I hope you want to redirect 404 pages only.

RewriteEngine on
ErrorDocument 404 /index.php
0
 

Accepted Solution

by:
sharingsunshine earned 0 total points
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
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.

771 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

13 Experts available now in Live!

Get 1:1 Help Now