php - 如何不在来自 AJAX POST 调用的文件上包含 htaccess 重定向

标签 php .htaccess

我有一个像这样的 htaccess 文件

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/(.*)$ /us/index.php?state=$1&city=$2 [L]

我有一个名为 getuser.php 的文件,它是一个从 index.php 中的 AJAX 调用中调用的 php 文件。如果我不使用重定向,调用工作正常,但由于重定向,我让它干扰 AJAX 调用并重定向 getuser.php 调用以及从帖子中重定向,这只会导致在顶部再次显示 index.php 文件我的当前页面。有没有一种方法可以让重定向不担心 AJAX 调用,这样它就可以在不影响当前重定向的情况下简单地在我的页面上显示我的结果。

我尝试添加以下内容,这只会导致 AJAX 中断而不工作,因为它不允许对 getuser.php 文件进行调用。如有任何帮助,我们将不胜感激。

RewriteCond %{REQUEST_URI} !/getuser\.php

最佳答案

试试这个,L 标志应该告诉 apache 这是最后一条规则,并且只转到请求的 url。

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/getuser\.php$ $0 [L]
RewriteRule ^([^/]+)/(.*)$ /us/index.php?state=$1&city=$2 [R=301,L]

关于php - 如何不在来自 AJAX POST 调用的文件上包含 htaccess 重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13962100/

相关文章:

apache - PHP : How to code . htaccess 使其无需编辑即可在本地主机和在线上运行

html - .htaccess 重写单页 anchor 规则(seo 友好)

php - fatal error : Call to a member function FetchRow() on a non-object

php - Symfony2 app_dev.php 只有错误 500 脚本过早结束

php - 帮助将 C++ 移植到 PHP 代码

php - 按表名 desc 分组不起作用

php - 输入按钮/ anchor 链接提交表单,其中指定了 POST 的 GET

apache - 重定向 https ://www to https://non-www - without seeing certificate error, 可能吗?

Apache .htaccess : Redirect to an URL containing a hashtag

php - 使用 htaccess 重写 Url 会使搜索引擎发现网站吗?