Need To Remove Appended %3F from URL.

I need to remove an encoded ? (%3F) off of several url's.  I want to use Mod_Rewrite to accomplish that.  Here is my regex but it itsn't working.

RewriteRule ^index\.php\?controller=cms&id_cms=([0-9]+)%3F$ /index.php?controller=cms&id_cms=$1 [R=301,L]

Open in new window

This is what the original url looks like

Open in new window

Please tell me how to get rid of the %3F appended to the url.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dr. KlahnPrincipal Software EngineerCommented:
The regex does not match the URL.  Two reasons.

1.  The URL begins with a slash.  The regex does not.  Add a leading slash on the regex.

2.  The URL contains no underscore between "cms" and "id" -- id cms.  The regex contains an underscore -- id_cms.  Replace the underscore with a space in the regex.
sharingsunshineAuthor Commented:
I have looked at your response numerous times and I see id_cms on the regex pattern and on the url.  So to remove this misunderstanding could you please show me what you have gotten to work in a tester.

Dr. KlahnPrincipal Software EngineerCommented:
On my screen there is no underscore between "id cms".

Missing space
Regarding testing the regex, as a long-time EE user you must know that testing with a regex tester is not a substitute for testing in the operational environment.  Only you can test on the actual system.
Get a highly available system for cyber protection

The Acronis SDI Appliance is a new plug-n-play solution with pre-configured Acronis Software-Defined Infrastructure software that gives service providers and enterprises ready access to a fault-tolerant system, which combines universal storage and high-performance virtualization.

sharingsunshineAuthor Commented:
Wow, that is strange.  Here is what I posted on the original question.

You are correct about testing but at least you can get close with a tester.

This is the tester I use and I did add the slash based on your suggestion but it still doesn't match
Steve BinkCommented:
Your original rule:
RewriteRule ^index\.php\?controller=cms&id_cms=([0-9]+)%3F$ /index.php?controller=cms&id_cms=$1 [R=301,L]

Open in new window

1.  As mentioned by Dr. Klahn, you may need to detect the initial '/', depending on other configuration.  An easy solution here is to make the initial slash optional.

2. The query string is not part of the test URL.  Instead, it is tested from within RewriteCond directives, using the %{QUERY_STRING} variable.

3. The percent character is considered special in mod_rewrite.  Escape it to allow for proper detection.

Altered ruleset:
RewriteCond %{QUERY_STRING} controller=cms [NC]
RewriteCond %{QUERY_STRING} id_cms=([0-9]+)\%3F [NC]
RewriteRule ^/?index\.php$ /index.php?controller=cms&id_cms=%1 [NC,R=301]

Open in new window

While that should detect the string properly, it is not very robust due to the variability of the query string.  It would be a better idea to clean the parameter once it is the application.  For example, in index.php (or an included handler), you might have something like this:
$id_cms = preg_replace('/[^0-9]/', '', $_GET['id_cms']);

Open in new window

@Dr. Klahn: I think you are having display issues in regards to the underscore.  It looks fine on my screen.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sharingsunshineAuthor Commented:
Great job, thanks so much for the help.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Regular Expressions

From novice to tech pro — start learning today.