Solved

.htaccess rewrite rules

Posted on 2013-12-04
3
184 Views
Last Modified: 2014-07-23
Can you write a rewriteRule for a .htaccess file that will accomplish the following:
redirect xyz.com/test and xyz.com/test/?id=1 to google.com
exclude xyz.com/tester and xyz.com/test/tester?

You must allow query strings and hash tags to flow through the redirects.

If I didn't need this solution asap I would spend the time to learn it myself but I unfortunately do not have the time. Thank you experts.
0
Comment
Question by:aristanoble
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 50

Assisted Solution

by:Steve Bink
Steve Bink earned 200 total points
ID: 39698630
Try this:
RewriteCond %{QUERY_STRING} ^id=1$ [OR]
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^/?test/?$ http://google.com [R,L,QSA]

Open in new window

As far as I know, there's no way to detect or act on a fragment.  Then again, I've not experimented with it much.  The fragment is a client-side instruction which is not generally important at the server level.
0
 
LVL 27

Accepted Solution

by:
skullnobrains earned 300 total points
ID: 39893176
assuming you want to redirect
/test
/test/?anything
but not
/test/
/test/anything_that_does_not_start_with_?

RewriteRule ^/?test(/?|$) http://google.com

if you're uncomfortable with the above, you might as well write multiple rewrite rules
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

726 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