apache - 使用通配符通过 .htaccess 重定向

标签 apache .htaccess mod-rewrite redirect url-rewriting

如何在 .htaccess 文件中进行通配符重定向?

我尝试使用以下内容,但 * 由于某种原因不起作用。

重定向 301/threads/*.343/http://myotherdomain.com/threads/*.343/

我无法使用 mod_rewrite,因为我需要执行 7000 个重定向,显然,当我尝试其中大约一半时,我的服务器抛出了 500 个配置错误错误。

因此,编写上述 7000 行代码似乎在某种程度上不那么密集。

无论如何,请让我知道如何在此类代码中表达通配符。

最佳答案

使用 mod_alias,您可以使用 RedirectMatch相反:

RedirectMatch permanent ^/threads/[^/]+\.343/$ http://myotherdomain.com$0

这会匹配所有与 /threads/*.343/ 匹配的 URL,* 是除 / 之外的任何字符。

关于apache - 使用通配符通过 .htaccess 重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15579531/

相关文章:

java - 每个文件计数的 WordCount 示例

php - 使用 apache 配置为每个站点指定 PHP 包含目录

.htaccess - CORS问题请求的资源上不存在 'Access-Control-Allow-Origin' header

spring - 在Apache中为其他端口重写规则

mod-rewrite - 无法创建锁定文件 TYPO3

Apache:在 .htaccess 中为目录设置 max-age 或 expires

django - Apache2 + VirtualEnv IOError : [Errno 13] Permission denied

php - HTTP 内容类型响应中的错误字符集

apache - Htaccess mod 重写不起作用

string - 在 .htaccess 中重写查询字符串