首页 > 解决方案 > 为什么我的重写规则导致所有 ajax 的错误 400?

问题描述

我有一个名为 {HTTP:CF-IPCountry} 的 geoip http 标头,它存储国家/地区代码,例如 FR、US 等。我需要做的是将此查询字符串 loc={HTTP:CF-IPCountry} 添加到网站主页https://example.com/test-website/以及具有以https://example.com/test-website/products/开头的 url 的任何页面,如果在url 所以如果用户请求页面https://example.com/test-website/products/shoe/?size=s它应该重写为https://example.com/test-website/products/shoe/?size= s&loc=我们

这就是 htaccess 文件现在的样子

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /test-website/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /test-website/index.php [L]

RewriteCond %{QUERY_STRING} !^loc [NC]
RewriteRule (.*) /%{REQUEST_URI}/?loc=%{HTTP:CF-IPCountry} [NC,NE,R,L,QSA]
</IfModule>

# END WordPress

我的最后一个重写器有 2 个我希望解决的问题 1-它在我的网站上的前端和 wordpress 管理面板上导致所有 ajax 出现 400 错误

2-我想将该 rewriteRule 应用到 2 个地方,目前该规则仅适用于主页和https://example.com/test-website/wp-admin/ 我想申请的那两个地方是...... a- 到网站主页https://example.com/test-website/ b- 到所有以https://example.com/test-website/products/开头的页面

谢谢

标签: phpregexapachemod-rewriteurl-rewriting

解决方案


推荐阅读