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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:19:40+00:00 2026-05-11T22:19:40+00:00

Say I have a rewrite that needs to pass the url to a PHP

  • 0

Say I have a rewrite that needs to pass the url to a PHP function and retrieve a value in order to tell what the new destination should be? is there a way to do that?

Thanks.

UPDATE:

Thanks so far guys..I am still having trouble but i’ll show you my code:

.htaccess

#I got the file path by echoing DOCUMENT_ROOT and added the rest.
RewriteMap fixurl prg:/var/www/vhosts/mydomain.com/httpsdocs/domain_prototype/code_base/url_handler.php

RewriteEngine On
RewriteRule (.*) ${fixurl:$1} [PT]

PHP:

set_time_limit(0); # forever program!
$keyboard = fopen("php://stdin","r");
while (1) {
        $line = trim(fgets($keyboard));
        print "www.google.com\n";  # <-- just test to see if working.
}

However I am getting a 500 Internal Server Error I am not sure if there is an error in my .htaccess or in my PHP?

  • 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-11T22:19:40+00:00Added an answer on May 11, 2026 at 10:19 pm

    There is something called a RewriteMap.

    You can call an executable script that will return the URL to rewrite to.

    Check this article for more information and examples (in Perl, but are totally applicable to any other language):

    http://www.onlamp.com/pub/a/apache/2005/04/28/apacheckbk.html

    Summary of caveats:

    • Must run a read STDIN loop (ie, don’t exit after receiving an URL)
    • Must print the URL to rewrite to WITH a trailing newline
    • Must be readable and executable by the user Apache runs as

    This is the way to create the map

    RewriteMap fixurl prg:/usr/local/scripts/fixit.php
    

    And now we can use it in a RewriteRule:

    RewriteEngine On
    RewriteRule (.*) ${fixurl:$1} 
    

    EDIT: About the Internal Server Error. The most probable cause is what Gumbo mentions, RewriteMap cannot be used in .htaccess, sadly. You can use it in a RewriteRule in .htaccess, but can only create it in server config or virtual host config. To be certain, check the error log.

    So, the only PHP / .htaccess only solution would be to rewrite everything to a certain PHP program which does the checking and redirects using the Location header. Something like:

    RewriteRule (.*) proxy.php?args=$1 [QSA]
    

    Then, in proxy.php

    <?php
          $url = get_proper_destination($QUERY_STRING); #args will have the URI path, 
                                                        #and, via QSA you will have
                                                        #the original query string
          header("Location: $url");
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a function called MyFunction(int myArray[][]) that does some array manipulations.
Say we have the following method: private MyObject foo = new MyObject(); // and
I have a script file for MySQL that needs to be run on about
Let's say I have some Classic ASP pages that produce all output via Response.Write.
I have a query that needs to return results that are NOT matched in
Let's say I have three value constructors: A { a :: Int } B
Let's say have something like: SELECT energy_produced, energy_consumed, timestamp1 AS timestamp FROM ( SELECT
Say I have the following file structure: app/ app.py controllers/ __init__.py project.py plugin.py If
Say you have an application divided into 3-tiers: GUI, business logic, and data access.
Say I have an ASMX web service, MyService. The service has a method, MyMethod.

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.