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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:56:59+00:00 2026-05-12T19:56:59+00:00

My script puts together a set of htaccess rules based on information passed into

  • 0

My script puts together a set of htaccess rules based on information passed into it and gives the user a downloadable text file with the rules printed out inside. The idea is that an administrator fills out some form information, clicks a downloadable link, gets a text file with the rules printed out inside, opens the file, copies the rules and pastes them into the htaccess file of their domain.

I’ve managed to put together the script that produces these rules. However, the text file seems to ignore all newline characters that I print to it. The tabs work, but the newlines do not. It must have something to do with the encoding I’m using with the header() function calls, but I’m not sure what I’m doing wrong. No amount of Googling as seemed to point me in the right direction. Any input would be appreciated.

Here’s the code:

header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="htaccess.txt"'); 
header('Content-Transfer-Encoding: binary');

$id = addslashes( $_GET['id']);
$location = addslashes( $_GET['location'] ); 
$location = substr($location, strpos($location, '/', 9 ) + 1 ) . ( ( substr( $location, strlen($location) - 1 ) == '/' ) ? '' : '/' );
$regEx = '([0-9a-zA-Z-_]*)';
$lines = array();

for( $x = 0; $x < 10; $x++ ) {
    $line = 'RewriteRule ^' . $location;
    for( $y = 1; $y <= $x; $y++ )
        $line .= $regEx . '/';
    $line .=  '*$' . "\t\t\t\t\t";
    $line .= "http://localhost/redirect.php?ring=$id";
    $line .= ( $x >= 1 ) ? '&link=$1' : '';
    $line .= ( $x > 1 ) ? '&tag' . ( $x - 1 ) . '=$' . $x . ' [NC]' . "\n" : "\n";
    $lines[] = $line;
}

foreach( $lines as $line )
    echo $line;
  • 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-12T19:56:59+00:00Added an answer on May 12, 2026 at 7:56 pm

    Are you testing on a windows system or a unix system? I seem to remember that unix systems use different line ending characters in text files than windows systems do.

    Wikipedia suggests

    “Another common problem is the use of
    ‘\n’ when communicating using an
    Internet protocol that mandates the
    use of ASCII CR+LF for ending lines.
    Writing ‘\n’ to a text mode stream
    works correctly on Windows systems,
    but produces only LF on Unix, and
    something completely different on more
    exotic systems. Using “\r\n” in binary
    mode is slightly better, as it works
    on many ASCII-compatible systems, but
    still fails in the general case. One
    approach is to use binary mode and
    specify the numeric values of the
    control sequence directly,
    “\x0D\x0A”.”

    http://en.wikipedia.org/wiki/Newline

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

Sidebar

Related Questions

I have a script that reads a form and puts some info into a
I have a build script where i create a text report file and output
The following shell script takes a list of arguments, turns Unix paths into WINE/Windows
I'd like to script, preferably in rake, the following actions into a single command:
I have a Perl script that I'm attempting to set up using Perl Threads
Here's a simple Ruby script: puts `ls -laG` In OS X's ls, -G is
I wonder why I should use: puts In folder #{File.join ENV[HOME], projects} Instead of:
I just put together a small script for a team of users that collects
I have a script which puts 803*803 (644 809) graph with 1 000 000
I have a python script that works great when run by itself. Based on

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.