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

  • SEARCH
  • Home
  • 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 6568847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:33:11+00:00 2026-05-25T14:33:11+00:00

Short Version: I wrote the question, and realized most people wouldn’t want to read

  • 0

Short Version:

I wrote the question, and realized most people wouldn’t want to read that much text. Consider the below reference, here’s the TL;DR:

I need to 301 redirect this url http://app.com/search/foo-bar/

to this url http://app.com/#!/search/foo-bar/

and send this: /foo-bar/, or anything else past /search/ to a server side script. In this case, it’s written in php.

Edit for clarity:

Current answers seem to focus on the rewrite to hashbang. That part is not the problem. The problem is that I lose any associated data when rewriting to a hashbang url, as the server side will see app.php as the location, not app.php/#!/foo-bar/ – So I need to capture foo-bar, and send it to the server somewhere other than in the URL. The rewrite works, and is not the issue. Thanks for your answers though!


Long Version:

Ok, so I have an interesting issue that has been tough for me to figure out.

The Scenario:

I have a backbone.js app that uses the hashbang for state:

app.com/#!/search/search-term/key-value/foo-bar/

In addition, I have google traffic coming to the site from the previous version that will be hitting “pretty url” style urls:

app.com/search/search-term/key-value/foo-bar/

I use an .htaccess mod_rewrite to swap the old url out for a hashbanged one if a user hits the legacy url.

I recently introduced a javascript-less bootstrapped version of the site that the site will be built on top of to gracefully downgrade and support crawlers. This is written using php.

For the php site to work, I need to pass in the values past the hashbang to the server side script, so I can figure out what to display.

The Problem:

When I transform a url and add an anchor, everything past the anchor (hashbang) is no longer sent to the request, so I don’t have access to it in php.

RewriteRule search/?(.*) #!/search/$1 [R=301,NC,L]

My options for sending things to the server side then are reduced to:
1. Query String
2. Environment Variables
3. Headers

So, I tried sending things via the query string

RewriteRule search/?(.*) #!/search/$1?filter=$1 [R=301,NC,L]

Obviously that didn’t work (the query is behind the anchor), so I tried it in front of the hashbang

RewriteRule search/?(.*) ?filter=$1/#!/search/$1 [R=301,NC,L]

That works, but is hideous and redundant to the end user. So, I thought I might try using environment variables.

RewriteRule search/?(.*) /!#/search/$1 [R=301,NC,L,E=FILTER:$1]

That failed, because environment variables aren’t preserved through a redirect (duh). I turned to using headers:

RewriteRule search/?(.*) /#!/search/$1 [R=301,NC,L,E=FILTER:$1]

Header set filterParams "%{FILTER}e"

But for some reason, the headers aren’t received by the page through the redirect. That seemed to make sense (although I’ve now stepped well outside of my comfort level with apache directives), so I tried echoing the header, in hopes that it would be passed, received by the second rewrite (that didn’t find search), and echoed out.

RewriteRule search/?(.*) /#!/search/$1 [R=301,NC,L,E=FILTER:$1]

Header set filterParams "%{FILTER}e"

Header echo filterParams

Nada – the filter doesn’t exist, so although it makes it to the server, it is null. My next thought was to attempt to employ some sort of conditional. Here was my attempt:

RewriteRule search/?(.*) legacy.php/#!/search/$1 [R=301,NC,L,E=FILTER$1]`

<FilesMatch "legacy.php">
    Header set filterParams "%{FILTER}e"
</FilesMatch>

Header echo filterParams

That didn’t seem to work either, so I’m stumped. I realize that I’ve spent so long on this that I probably have the solution within my grasp and I’m just tired of looking at it, or it’s not even remotely possible, even with gross header hacking.

Anyone have a clue how to to this?

  • 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-05-25T14:33:12+00:00Added an answer on May 25, 2026 at 2:33 pm

    AFAIK, there’s no good way to preserve variables through redirect without sticking them in the query string…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Short version of question: How do I get started with C programming? Note that
Short version of the question: If you have a table with a large number
Ok, the short version is that I have a Linq entity from a LinqDataSourceUpdateEventArgs
this is pretty much an updated version of question I've already asked. I am
Short version of the question here, I run an exceutable (which in turn runs
Short Version I want to extend SoapClient so it does this internally when accessing
Short version : VB.Net Windows forms feature controls that are often dragged from the
Short version: What is the cleanest and most maintainable technique for consistant presentation and
The short version: is there a way to to write an and or an
Short version: Can I grant access to external databases to a role? Long version:

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.