Solved

.htaccess rewrite rules

Posted on 2013-12-04
3
183 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
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Import data into excel from web page 10 101
PowerShell Regular Expression 2 50
Allow space in this pattern 2 63
Adding multiple JVM environments to RedHat 6 7 45
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

809 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