Returning html codes from ajax with .htaccess - php

returning html codes from ajax post process
javascript side
$('#bgn').live('click',function(){
var d = {islem:'bugun'};
$.post('inc/ajax.php',d,function(v){
$('#sol').text(v);
});
});
php side
<?
include "connect.php";
session_start();
if($_POST['islem']=='bugun')
{
echo 'furkan<br>furkanfurkan<br>furkan<br>furkan<br>furkanfurkan
<br>furkan<br>furkan<br>furkan';
}
?>
dont write into the #sol div "furkanfurkan"
returned html codes to #sol div
coming data is "...."
why?
if i don't use .htaccess this problem is solved
but i should use .htacess
please help me
sorry for my bad english
thanks for answers, i edit for var d = {islem:'bugun'};
i was edited this line but don't solved my problem
this my .htaccess page
RewriteEngine On
RewriteRule ^baslik/(.*)/$ baslik.php?id=$1&s=1
RewriteRule ^baslik/(.*)/(.*)$ baslik.php?id=$1&s=$2
RewriteRule ^kayit$ index.php?islem=yazarol
RewriteRule ^giris$ index.php?islem=giris
RewriteRule ^hakkinda$ index.php?islem=credits
RewriteRule ^istatistik$ index.php?islem=stat
RewriteRule ^mesajlar$ inc/mesaj.php
RewriteRule ^mesajlar/(.*)$ inc/mesaj.php?to=$1
RewriteRule ^yonetim-paneli$ adm.php
RewriteRule ^panel$ inc/panel.php
RewriteRule ^cikis$ index.php?islem=logoff
RewriteRule ^linkolustur/(.*)$ inc/paylas.php?id=$1
RewriteRule ^profil/(.*)$ inc/profil.php?id=$1
RewriteRule ^entry/(.*)$ inc/entry.php?id=$1
RewriteRule ^kimleronline$ inc/online.php
RewriteRule ^nick_to_mail$ index.php?islem=mail_bul
RewriteRule ^yazaramsj/(.*)$ inc/to.php?to=$1
RewriteCond %{HTTP_HOST} ^www.sozluksau\.com [NC]
RewriteRule ^(.*)$ http://sozluksau.com/$1 [L,R=301]
ErrorDocument 404 /index.php?islem=sayfayok
SOLVED :) thanks #dianuj
changed this
first add this line to .htaccess
RewriteRule ^call_my_ajax$ inc/ajax.php
and after change this
$.post('http://mysite.com/call_my_ajax',d,function(){)

You have to get the post value by $_POST['p'] because you have made your data string to send by var d = {p:'bugun'}; and getting post variable by $_POST['islem'] which is wrong
<?
include "connect.php";
session_start();
if($_POST['p']=='bugun')
{
echo 'furkan<br>furkanfurkan<br>furkan<br>furkan<br>furkanfurkan
<br>furkan<br>furkan<br>furkan';
}
?>
And change the text() to html()
$('#sol').html(v);
Edit
Change your ajax url to something and add one new rule in .htaccess
$.post('call_my_ajax',d,function(v){
$('#sol').text(v);
});
in .htaccess
RewriteRule ^call_my_ajax$ inc/ajax.php

I'm afraid some of your English is not very clear. But as I understand your code works if you don't have an .htaccess file but breaks when you do have this file.
So I would guess your .htaccess file is causing the problem. What I would do in your situation is:
Install the program Fiddler2 and get it running (this lets you see the contents of all the requests and responses to your webserver).
Try using your website with and without the .htaccess file and look at what the responses look like for ajax calls to .../inc/ajax.php. I think you might find a helpful error message there.

Related

How to set .htaccess for 2 type get value on the same page?

For this page test.php
i have to use 2 format url
www.example.com/test/1234
and
www.example.com/test/1234/abcd
My .htaccess is
RewriteRule ^test/([^-]*)/([^-]*)$ /test.php?one=$1&two=$2 [L]
It's work good with www.example.com/test/1234/abcd but redirect internal error with www.example.com/test/1234
I want to know how can i edit .htaccess for work good with my 2 url format on test.php ?
Try the following instead:
RewriteRule ^test/([^-]*)$ /test.php?one=$1&two=$2 [L]
Just remove the 2nd /([^-]*) it is making no difference, as you can see here. Removing it will allow for you to access www.example.com/test/1234 too.
You can use:
RewriteRule ^test/([^/-]+)(?:/([^-]*))?$ /test.php?one=$1&two=$2 [L]

RewriteRule and PHP: Adding a new '?param=yes' to the URL

I've got hundred of webpages already created with RewriteRules and PHP
foo.com/section/item/number --> foo.com/section.php?item=number
foo.com/story/number ---> foo.com/story.php?id=number
Now I would like to include an extra parameter for all the webpages
foo.com/section/item/1?param=yes
foo.com/story/34?param=yes
I tried with:
if (isset($_REQUEST['param']))
{
print "IT WORKS!";
}
It works only with 'foo.com' (the 'index.php') with no RewriteRule.
I tried also by adding QSA to the RewriteRule
RewriteRule ^story/([^/]+) /story.php?id=$1 [L, QSA]
What am I doing wrong? Thank you very much.
I'm not able to test, but I think this will do what you need
RewriteCond %{QUERY_STRING !&param=yes
RewriteRule ^/?c/(.*)$ /%1?%{QUERY_STRING}&&param=yes [L]
First this makes sure if a request already has param=yes in it, do nothing, otherwise append either ?param=yes or &param=yes , if the request already has ? in it.

.htaccess redirect subfolders

Im struggling with a .htaccess settings to get following:
To create Multi-language functionality in my CMS without duplicating the productdatabase I would like to get the content of the default language, but keeping the right url in the addressbar.
For example:
http://www.myshop.com/en/webshop get the content of http://www.myshop.com/webshop
http://www.myshop.com/en/collection get the content of http://www.myshop.com/collectie
And also for the products:
http://www.myshop.com/en/webshop/item1 get content of http://www.myshop.com/webshop/item1
http://www.myshop.com/en/collection/product1 get the content of http://www.myshop.com/collectie/product1
In short:
In case of calling the folders '/en/webshop/' and '/en/collection/' there must be a rewrite to '/webshop' and '/collectie'.
Anyone got a clue?
Thanks in advance...
What about:
RewriteEngine on
RewriteRule ^/?en/webshop/(.*)$ /webshop/$1
RewriteRule ^/?en/collection/(.*)$ /collectie/$1
The first line just enables mod_rewrite
The second line (1st rule) matches anything under /en/webshop and discards the /en
The third line is similar to the second but it also "renames" collection to collectie
If you have more folders/paths you want to redirect I 'd suggest adding the rule:
RewriteRule ^/?en/(.*)$ /$1
which is rewriting anything that starts with /en.
Hope it helps, note it is not tested
Use below rule:-
RewriteEngine on
RewriteRule ^en/(.*)$ /$1 [L,R=301,QSA]
OR
RewriteEngine On
RewriteRule ^(.*)/en/(.*)$ $1/$2 [R=301,L]
Hope it will help you :)

url rewrite not reading in php

I am beginner in url rewriting and i have studied about it from various sources.Everything seems to be working till now but this is just not working.
I have this line of code in my htaccess file.
RewriteRule ^notice/all/page/([0-9]+)/?$ files/all_notice.php?show=all&page=$1 [NC,L]
This is the url i am visiting
http://localhost/notice/all/page/1
and when reading variables in php like this-
<?php
$type=$_GET['show'];
$page=$_GET['page'];
echo $type.'--'.$page;
?>
This is what i get
all--notice
I am getting the show variable as it is but instead of page number i am getting notice.
What is going wrong?
Your RewriteRule is this:
RewriteRule ^notice/all/page/([0-9]+)/?$ files/all_notice.php?show=all&page=$1 [NC,L]
Try this:
RewriteRule ^notice/all/page/([0-9]+)/?$ /files/all_notice.php?show=all&page=$1 [L]
The only difference is the addition of a / in front o files/… and removing the NC so it is only [L].
EDIT: And perhaps you should see what happens if you change that $1 to $2, $3 or even $4 to see if any of those values get passed through.
Try this:
RewriteRule ^notice/all/page/([0-9]+)?$/ files/all_notice.php?show=all&page=$1 [NC,L] //for urls like localhost/notice/all/page/1/
RewriteRule ^notice/all/page/([0-9]+)?$ files/all_notice.php?show=all&page=$1 [NC,L] //for urls like localhost/notice/all/page/1
You have ?$ after the / but it should be after the regex class

Can't access post or get from a php page after redirecting

I'am redirecting about 100 hmtl pages to a single PHP page (example.php) using .htaccess. It is working perfectly.
I've pagination on that page (example.php) but I am using the original HTML page URL (example.html?page=2&limit=20)
so example.html, example1.html, example2.html, example3.html are all redirecting to example.php.
The address bar is still showing ".html" URL but due to .htaccess redirection the example.php is rendering.
when is click on a pagination link (example.html?page=2&limit=20) the browser address bar shows correct .html URL and query string.
I've tried to get the values of page, and limit using $_GET and $_REQUEST in (example.php) but i am not successful.
Please help me in reading the (example.html?page=2&limit=20) query string parameeters .
Edit Code ported from comments:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !^page-(.*)$
RewriteRule ^page-(.*)$ size-content.php?sef=$1 [L]
Add the QSA flag, which means "query-string append" to be sure the existing query string is ported into the rewritten URL.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !^page-(.*)$
RewriteRule ^page-(.*)$ size-content.php?sef=$1 [L,QSA]
.htaccess modify your server configuration.
if you are making redirection then you change your request.
Try mod_rewrite if you are using Apache of course.
RewriteEngine On
RewriteRule ^example\.html\?(.*) example.php?$1
Mod rewrite is module to Apache. It is not allowed on most free hostings.
Yasir - you can resolve this problem by two ways:
1) Re-write rules for .htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !^page-(.).html(.)/(.)$
RewriteRule ^page-(.).html(.)/(.)$ size-content.php?sef=$1&page=$2&limit=$3 [L]
This rule will handle: page-example.html?page=2&limit=20
I hope - you will easily understand the above rule.
Note: Keep one thing in your mind that every link should be in same pattern if you change rule in htaccess.
2) You can resolve this problem on your "size-content.php"
Suppose page-example.html?page=2&limit=20
$_GET['sef'] = example.html?page=2&limit=20 [according to you .htaccess]
Now you can parse this string via explode function
Thanks

Categories