Solved

.htaccess rewrite rules

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
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.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

744 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

13 Experts available now in Live!

Get 1:1 Help Now