【问题标题】:htaccess rewrite and submit form not working togetherhtaccess 重写和提交表单不能一起工作
【发布时间】: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


【解决方案1】:

我不知道错误是什么,带有斜杠或数字和 htaccess 但我找到了解决方案

RewriteRule ^read/([A-Za-z0-9\-_]+]*)$ file.php?url=$1 [L] 

没有html或php

【讨论】:

    【解决方案2】:

    尝试将您的 2 条规则更改为:

    RewriteRule ^([a-zA-Z0-9-/]+).html$ file.php?url=$1.html [QSA,L]
    RewriteRule ^([a-zA-Z0-9-/]+).html/$ file.php?url=$1.html [QSA,L]
    

    .html 被剥离,所以你的 file.php 脚本被调用如下:

    http://site.com/file.php?url=2012/08/15/My-html-page
    

    而不是

    http://site.com/file.php?url=2012/08/15/My-html-page.html
    

    【讨论】:

    • 对不起,我忘了提到我添加了一个带有 html $url=$url.'.html' 的 php 变量;我对帖子做了一些修改
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-05-26
    • 1970-01-01
    • 2014-11-21
    • 1970-01-01
    • 2018-02-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多