通过.htaccess重定向AJAX查询

编程入门 行业动态 更新时间:2024-10-26 22:28:04
本文介绍了通过.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查询

本文发布于:2023-10-31 19:19:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1547034.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   htaccess   AJAX

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!