通过.htaccess重定向AJAX查询 [英] Redirect AJAX query by .htaccess

查看:56
本文介绍了通过.htaccess重定向AJAX查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个.htaccess文件:

I have a .htaccess file:

RewriteEngine On
DirectoryIndex control.php
Options +FollowSymlinks
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.+) controller.php?do=$1 [L]

这将重定向所有查询并设置干净的URL.但是,当我使用ajax时,它也会重定向.是否可以过滤Ajax查询并重定向到

This redirects all queries and sets up clean URLs. But when I use ajax it redirects that too. Is it possible to filter ajax queries and redirect to

controller-ajax.php?do=$1 [L]

相反?

我试图在controller.php中捕获它,但是 X_REQUESTED_WITH 不存在.最好的办法是将所有ajax请求重定向到另一个脚本,而不进行其他脚本检查.

I was trying to catch it in controller.php, but X_REQUESTED_WITH doesn't exist. The best thing then would be to redirect to another script all ajax requests, and not make an additional script check.

推荐答案

调用AJAX时,将GET变量添加到查询中(即在查询末尾添加?ajax = true ).然后在您的.htaccess文件中添加该文件:

When you call AJAX, add a GET variable to the query (i.e. add ?ajax=true to the end of the query). Then have this in your .htaccess:

RewriteEngine On
DirectoryIndex control.php
Options +FollowSymlinks
RewriteBase /

RewriteCond %{REQUEST_FILENAME} -f {OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - [L]

RewriteCond %{QUERY_STRING} ajax.true
RewriteRule (.+) controller-ajax.php?do=$1 [L]

RewriteRule (.+) controller.php?do=$1 [L]

这篇关于通过.htaccess重定向AJAX查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆