【发布时间】:2012-08-11 22:47:50
【问题描述】:
经过几次研究放弃并在这里发帖,如果有人可以澄清我的事情,那就太好了,谢谢
当我使用http://site.com/file.php?url=2012/08/15/My-html-page 时一切正常,ajax 将帖子发送到 file.php 并显示它,但是当我使用由 htaccess url http://site.com/2012/08/15/My-html-page.html 重写的帖子表单时,它什么也不做
链接:
原文:http://site.com/file.php?url=2012/08/15/My-html-page
用 htaccess 重写:http://site.com/2012/08/15/My-html-page.html
数据库条目:2012/08/14/My-first-post
要添加我添加的html agter 页面
$url=$url.'.html';
$url= $_GET["url"];
我在file.php中的ajax
<SCRIPT language="JavaScript">
$(function() {
$(".comment_button").click(function()
{
var element = $(this);
var note = $("#note").val();
var dataString = 'note='+note;
if(note=='')
{
$('#flash').fadeIn("fast");
}
else
{
$.ajax({
type: "POST",
url: "file_post.php",
data: dataString,
cache: false,
success: function(html){
$('body').load('/<? echo $url ?>.html');
}
});
}
return false;
});
});
</script>
我在file.php中的表单
<form name="comment" method="post" action>
<button class="comment_button" type="submit"><span>Отправить</span></button>
<textarea name="note" id="note"></textarea>
</form>
我在file_post.php中的php文件
if(isSet($_POST['note'])) {
$note=$_POST['note'];
$note = html_entity_decode($note);
$date=date("Y-m-d");
$time=date("H:i:s");
$table = "insert into comment (note, date, time) values ('$note', '$date', '$time');";
mysql_query($table);
}
我的 htacces
Options +FollowSymLinks
Options -Indexes
RewriteEngine On
RewriteBase /
<Files inc/config.php>
deny from all
</Files>
RewriteRule ^([a-zA-Z0-9-/]+).html$ file.php?url=$1 [QSA,L]
RewriteRule ^([a-zA-Z0-9-/]+).html/$ file.php?url=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
重写页面上的 $_SERVER['REQUEST_URI'] 给了我一个空输入,这正常吗?
【问题讨论】:
-
检查这个stackoverflow问题:stackoverflow.com/questions/358263/…
-
可能问题出在 RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.php
-
我用它来从文件中删除 PHP
标签: php jquery ajax .htaccess rewrite