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 5840341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:43:47+00:00 2026-05-22T11:43:47+00:00

I’ve inherited a site with hundreds of scattered HTML and non-framework PHP files, which

  • 0

I’ve inherited a site with hundreds of scattered HTML and non-framework PHP files, which I am porting to Ruby on Rails 3.0.

As functionality is added in the Rails app, the corresponding pages are deleted from the document root; but, because there are often links to these in Google or from external sites, simply returning a 404 is not acceptable.

A URL like ‘/contact.php’ should redirect to ‘/app/contact/’, for example.

For the first few cases of this, I created simple stub html files at the old locations, with Meta tags within to perform the redirect. This doesn’t scale well, particularly once I start replacing product pages, of which there are thousands.

My preference is to delete the old pages, then have the 404 handler dispatch these to the new Rails app, which will examine the URL using regexes and database lookup to try to figure out what the replacement page is, then issue a 301 redirect to that new page.

In httpd.conf, I placed the directive:

ErrorDocument 404 /app/error/handle404
# /app/error is a rails url.

When I hit “http://localhost/does-not-exist”, this causes my ErrorController to be invoked, as expected.

However, within the controller, I cannot find the original path (“/does-not-exist”) anywhere in request, request.headers, or ENV – I’ve been calling likely methods like request.request_uri (which contains /app/error/handle404), and examining request.headers and ENV without finding the expected original path.

The Apache access_log shows only the request for /does-not-exist, indicating that it transparently invoked /app/error/handle404 (without doing a redirect or causing a second request to be made).

How can I get access to the original URL?

Edit: to clarify, here is the sequence of events:

  1. User hits legacy path like http://mysite/foo.php, probably coming from some ancient link from a blog.
  2. …but foo.php no longer exists!
  3. this is a 404, thus Apache invokes ErrorDocument
  4. directive is “ErrorDocument 404 /railsapp/error/handle404”
  5. Rails routes this to ErrorController action “handle404” – this is working correctly
  6. problem: in ErrorController, request.request.uri, request.headers do not provide any clue as to which URL the user was actually trying to get to, like “/foo.php”; I need to know the original URL to serve up an appropriate replacement page.
  • 1 1 Answer
  • 3 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-22T11:43:48+00:00Added an answer on May 22, 2026 at 11:43 am

    As I couldn’t find the original, non-rewritten URL in the Rails request, I ended up doing it in PHP – plain, old-fashioned, non-framework PHP with explicit mysqli_*() calls.

    The PHP error handler receives the necessary information in the $_SERVER hash; $_SERVER[‘REQUEST_URI’] contains the original URI that I needed.

    I look this up in a database, and if I find a corresponding entry, issue a 301 redirect to the new location; if there’s no entry, I simply display a 404 page to the user.

    Simplified (PHP):

    $url = $_SERVER['REQUEST_URI'];
    $redir = lookupRedirect($url);   # database stuff here
    if (! $redir) {
        include ('404.phtml');
    } else {
        header("Status: 301");
        header("Location: " . $redir['new_url']);
    }
    

    It’s an ugly kluge, but I just couldn’t find a way to make the Rails app aware of the error URL.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have thousands of HTML files to process using Groovy/Java and I need to
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into

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.