Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8739709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:59:25+00:00 2026-06-13T10:59:25+00:00

All, I am redirecting some urls with specific query strings to new page .

  • 0

All,

I am redirecting some urls with specific query strings to new page . For example http://testserver.xyz.com/abc/content/content.jsp?contentId=123 or http://testserver.xyz.com/abc/content/content.jsp?contentId=345 needs to be redirected to http://ww2.newtestserver.com/xyz.html

For this purpose i wrote following redirects:

RewriteCond %{QUERY_STRING} contentId=123 [OR]
RewriteCond %{QUERY_STRING} contentId=345 [OR] 
RewriteCond %{QUERY_STRING} contentId=678 
RewriteRule ^/(.*)$ http://ww2.newtestserver.com/xyz.html/? [R=301,L]

This works fine except when i type in my browser http://testserver.xyz.com/abc/content/content.jsp?contentId=1234. This also gets redirected to http://ww2.newtestserver.com/xyz.html.

I do not want this. how can i prevent this so that my mod rewrite only looks at query string 123 or 345 or 567 but not something 123x or 345x or 678x?

Please help

TIA

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T10:59:26+00:00Added an answer on June 13, 2026 at 10:59 am

    To make sure that the rewrite looks only at the exact query strings you specified, you should tell it that those are the full query strings using ^ and $. ^ matches the beginning of the string, and $ matches the end.

    RewriteCond %{QUERY_STRING} ^contentId=123$ [OR]
    RewriteCond %{QUERY_STRING} ^contentId=345$ [OR]
    RewriteCond %{QUERY_STRING} ^contentId=678$
    RewriteRule ^/(.*)$ http://ww2.newtestserver.com/xyz.html [R=301,L]
    

    The above code will work. The code below might work (and should be more efficient), but I’m not at a computer I can test on right now.

    RewriteCond %{QUERY_STRING} ^contentId=(123|345|678)$
    RewriteRule ^/(.*)$ http://ww2.newtestserver.com/xyz.html [R=301,L]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on redirecting all files in the URI(?) www.gdlsk.com/practice to this new
I've got an issue where Rails is for some reason redirecting the new and
Suppose you have an old legacy website, with an in-house php CMS. http://mysite.com/index.php?page=3&c=7 Now,
I have a tricky issue redirecting some URLs internally for my site. The situation
There are some Wordpress plugins for permanent redirection of all 404's to the main
All, If I run a query like the following: $qry = Select wrong_column from
all. We're trying to get some intersect collisions working, but the problem experience is
All my files can be found on GitHub: https://github.com/Integralist/Passage (just in case you need
A login page on our asp.net website uses https – while almost all of
Am redirecting urls from a legacy site, which gets me to a url like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.