Tomas S. Tomas S. - 7 months ago 43
MySQL Question

URL rewrite with .htaccess make duplicate mysql entries

If rewrite url with .htaccess, all INSERT query with php is performed twice (unwanted duplication)

My .htaccess:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

And index.php:

<?php define('DB_LOGIN', 'mylogin');
define('DB_PASS', 'mypass');
define('DB_HOST', 'localhost');
define('DB_TYPE', 'mysql');
define('DB_NAME', 'dbname');

$mysql = MySQL_Connect(DB_HOST, DB_LOGIN, DB_PASS);
$mysql_db = MySQL_Select_DB(DB_NAME);

mysql_query("INSERT INTO `pages` (`title`, `slug`) VALUES ('TEST', 'test')"); ?>

After one load of index.php, I have two same entries in mysql.
All is OK when I remove .htaccess, so, problem must be there. The rewrite definition in .htaccess is taken from Wordpress - i like it.

I try Medoo framework, but entries is still duplicate.

So, any suggestion? :-)


Browsers automatically request the favicon.ico file by default.
But you don't have any favicon.ico file so it is rewritten (rule in your htaccess).
This is why you have a duplicate execute.


  1. Add a favicon.ico file
  2. Don't INSERT (in index.php) if url requested is favicon
  3. Disallow it in your htaccess with a rule