gpt4 book ai didi

regex - .htaccess 替换一个词后重定向?

转载 作者:行者123 更新时间:2023-12-02 06:45:40 25 4
gpt4 key购买 nike

我需要使用 .htaccess 文件来替换 URL 中的单词;像这样:

示例网址:

 http://example.com/oldword/test-page.html

重定向到:

 http://example.com/newword/test-page.html

我如何使用 mod_rewrite 将包含 /oldword/ 的每个 URL 在替换该词后重定向到相同的 URL?

最佳答案

这应该为你做:

RewriteRule ^oldword/(.*)   /newword/$1   [L]

编辑:根据您的 RewriteBase 设置,它可能无法完全正常工作,但它会很接近。

第二次编辑:如果您需要将 301 Moved Permanently header 与旧 URL 相关联,您也可以这样做:

RewriteRule ^oldword/(.*)   /newword/$1   [R=301,L]

关于regex - .htaccess 替换一个词后重定向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/799809/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com