regex - 重定向主页,但如果存在查询字符串则不重定向

标签 regex apache .htaccess mod-rewrite

我只想重定向 WordPress 网站的主页,但前提是原始 URL 上不包含任何查询字符串。这有效:

RedirectMatch 307 ^/$ http://www.consumerenergyreport.com/ticker

...但是通过查询重定向 URL。我尝试过:

RewriteCond ! %{QUERY_STRING}

...但这似乎不适用于 RedirectMatch,只能使用 RewriteRule(如图)。

有什么想法吗?提前致谢!

最佳答案

在 .htaccess 文件中尝试此规则:

Options +FollowSymlinks -MultiViews
RewriteEngine on

RewriteCond %{QUERY_STRING} ^$
RewriteRule ^/?$ /ticker [R=307,L]

关于regex - 重定向主页,但如果存在查询字符串则不重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5813273/

相关文章:

c# - Regex.Split 可以得到多个空格吗?

html - 如何从 URL 中删除 .html?

php - 启用 .htaccess 时 Joomla 3.8 出现 404 错误

正则表达式匹配所有以 n 个字符开头的序列

java 正则表达式 : word chracters and white spaces

java - 如何使用正则表达式从字符串中提取时间?

php - 编译PHP 7时未找到Apache a2enmod,但这是必需的

apache - Cloudflare SSL 握手失败(错误 525)

node.js - proxyPass 适用于浏览器,但不适用于网络请求

.htaccess - 如何使 Zend Framework 2 与 nginx 一起工作?