Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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]
</IfModule>

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? :-)

like image 626
Tomas S. Avatar asked Nov 11 '22 14:11

Tomas S.


1 Answers

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.

Solutions:

  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
like image 118
Justin Iurman Avatar answered Nov 14 '22 22:11

Justin Iurman