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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:54:59+00:00 2026-06-09T18:54:59+00:00

I have a problem with understanding mod_rewrite behavior. I’ll illustrate this with an example.

  • 0

I have a problem with understanding mod_rewrite behavior.
I’ll illustrate this with an example.
I have 3 files in my root directory: .htaccess, index.php and test.php.
The content of files:

.htaccess

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.+) ?link=$1 [L]

index.php

<?php
$db = mysqli_connect('localhost', 'root', '', 'mydb'); 
$db->real_query ("INSERT INTO `test` (`str`) VALUES ('test_string')");
print_r($_GET);
?>

test.php

<?php
$db = mysqli_connect('localhost', 'root', '', 'mydb'); 
$db->real_query ("INSERT INTO `test` (`str`) VALUES ('another_test_string')");
print_r($_GET);
?>

So when I go to my site’s root folder with the browser, two strings are inserted in database – ‘test_string’ and ‘test_string’. If I go to /test.php, also two strings will be inserted – one from index.php script – ‘test_string’ and one from test.php string – ‘another_test_string’. If I remove rewrite rules from .htacess, only one string will be inserted for both pages. I cannot understand such behavior – why all scripts are executed twice? And especially I don’t understand why this happens with test.php since I wrote RewriteCond %{REQUEST_FILENAME} !-f, so no rewrites should be done.

Thank you in advance.

  • 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-06-09T18:55:00+00:00Added an answer on June 9, 2026 at 6:55 pm

    The php code you have will insert into the database once that fragment of code is processed.

    If you execute it more than once, you will see more inserts in the database.

    However rewrite rules are executed once only, too.

    So what you experience is likely totally unrelated with your rewrite rules. If you do not trust me, enable logging for the rewrites (see apace docs) and follow the trail.

    You probably have sit too long in front of the computer, so just get a cup of tea, relax and find that bug.

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

Sidebar

Related Questions

I have problem understanding this one: <?php $string = 'April 15, 2003'; $pattern =
i'm starting to work with php basics and i have some problem understanding how
I have following files and directories in my project root directory main.py bar.py foo
I have problem understanding the order in which initialization happens. this is the order
I have a little problem understanding XMLHttpRequest 's handlers. The specification says this about
I have a problem in understanding OOP... This is it : Sometime's you create
Hi I have problem understanding the code below: foreach ($_POST as $field=>$value) { $this->ipn_data[$field]
I have a problem understanding this structure , would love to get a clear
I have this problem understanding how to save data in order to have an
I'm not sure how to describe this best. But I have a problem understanding

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.