regex - 301 .htaccess 从具有 "?"字符的 URL 重定向

标签 regex apache .htaccess redirect seo

我想在 .htaccess 中重定向每个包含“?”的 URL。字符添加到我网站的根目录 (domain.com)。

我读过这个:

301-htaccess-redirect-with-special-characters
/how-to-make-htaccess-rule-for-a-url-with-specific-characters

但是我还是不知道该怎么做。我只知道一点正则表达式。

示例 Urls 我想重定向到我网站的根目录:

http://www.portaltarot.com/index.html?url=/MHL-Papus.html http://www.portaltarot.com/index.phpindex.php?Itemid=249

最佳答案

你需要使用 mod_rewrite 来做到这一点,所以像这样:

RewriteEngine On

RewriteCond %{QUERY_STRING} ^url=/MHL-Papus.html$ 
RewriteRule ^index\.html$ / [L,R=301]

RewriteCond %{QUERY_STRING} ^Itemid=249$
RewriteRule ^index\.phpindex\.php$ / [L,R=301]

关于regex - 301 .htaccess 从具有 "?"字符的 URL 重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24614452/

相关文章:

apache - Codeigniter URL 重定向,无需添加 index.php

linux - Windows 生产服务器上的 Drupal 7 和 WordPress 3.8?

.htaccess - 重写基本: from specific url to another specific url

.htaccess - SEO 友好的 URL

.net - 为什么RegularExpressionValidator中的 "\d+{1,4}(?:[.,]\d{1,4})?"抛出异常: "Nested quantifier {"

ruby - 一个哈希中的多个子哈希

javascript - Python/JS 正则表达式匹配任何小于 X 的数字

regex - 我如何在没有某些足够的情况下进行正则表达式?

.net - 我可以使用 Linux/Mono 来部署 aspnet web 应用程序吗?

php - 如何调用magento主安装子文件夹中的多个网站商店?