0

after several researches a give up and post here , if someone could clearify me a things , it would be nice, thanks

When i use http://site.com/file.php?url=2012/08/15/My-html-page all works fine , ajax sends a post to file.php and display it , but when i use a rewrited by htaccess url http://site.com/2012/08/15/My-html-page.html post form do nothing , it dosent work

Links:

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

Rewrited with htaccess: http://site.com/2012/08/15/My-html-page.html

The database entry : 2012/08/14/My-first-post

To add a html agter pages i added

$url=$url.'.html'; 
$url= $_GET["url"];

My ajax that in file.php

<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> 

my form that in file.php

 <form name="comment" method="post" action>

 <button class="comment_button" type="submit"><span>Отправить</span></button>
 <textarea name="note" id="note"></textarea>
 </form> 

My php file in file_post.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);


}

My 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

the $_SERVER['REQUEST_URI'] on rewrited page gives me a empty input , its normal ?

warfish
  • 613
  • 5
  • 20
  • check this stackoverflow question:http://stackoverflow.com/questions/358263/htaccess-is-it-possible-to-redirect-post-data – Niborb Aug 15 '12 at 16:18
  • maybe the problem is in RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.php – warfish Aug 15 '12 at 18:43
  • i use it for remove the PHP from files – warfish Aug 15 '12 at 18:43

2 Answers2

0

Try changing your 2 rules to:

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]

The .html is getting stripped so your file.php script is getting called like:

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

instead of

http://site.com/file.php?url=2012/08/15/My-html-page.html
Jon Lin
  • 142,182
  • 29
  • 220
  • 220
  • im sorry i forget to mention i add a php varible with html $url=$url.'.html'; i made some changes to the post – warfish Aug 15 '12 at 18:49
0

i dont know what was the error , something with a slashes or numbers and htaccess but i found a solution with

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

without html or php

Karuppiah RK
  • 3,894
  • 9
  • 40
  • 80
warfish
  • 613
  • 5
  • 20