Solved

.htaccess rewrite rules

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

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

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.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

911 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

18 Experts available now in Live!

Get 1:1 Help Now