Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要创建一个 htaccess 规则,将变量(如果存在)从 request_uri 传递到目标 url。
因此,如果请求 url 包含“test=something”,如果它还没有包含“test”var,它应该将它添加到新的 url。
提前致谢。
您可以在DOCUMENT_ROOT/.htaccess文件中使用此代码:
DOCUMENT_ROOT/.htaccess
RewriteEngine On RewriteCond %{QUERY_STRING} !(?:^|&)test=[^&]+ [NC] RewriteCond %{HTTP_REFERER} /index\.php\?(?:.+?&)?(test=[^&]+) [NC] RewriteRule ^index\.php$ %{REQUEST_URI}?%1 [L,QSA,NC,R=302]
但是请记住,这HTTP_REFERER可能会被客户欺骗。
HTTP_REFERER