用.htaccess重写的URL使重复的mysql条目 [英] URL rewrite with .htaccess make duplicate mysql entries
问题描述
如果使用.htaccess重写url,则使用php进行的所有INSERT查询都会执行两次(不需要的重复操作)
If rewrite url with .htaccess, all INSERT query with php is performed twice (unwanted duplication)
我的 .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>
和 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')"); ?>
在加载index.php之后,我在mysql中有两个相同的条目. 当我删除.htaccess时,一切正常,因此,问题一定在那里. .htaccess中的重写定义来自Wordpress-我喜欢它.
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.
我尝试使用Medoo框架,但是条目仍然重复.
I try Medoo framework, but entries is still duplicate.
那么,有什么建议吗? :-)
So, any suggestion? :-)
推荐答案
浏览器默认情况下会自动请求favicon.ico文件.
但是您没有任何favicon.ico文件,因此将其重写(您的htaccess中的规则).
这就是为什么您有重复执行的原因.
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.
解决方案:
- 添加favicon.ico文件
- 如果请求的网址是网站图标,则不要插入(在index.php中)
- 使用规则在您的htaccess中禁止使用它
这篇关于用.htaccess重写的URL使重复的mysql条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!