htaccess 重定向 URL 到另一个并删除字符

Htaccess redirect URL to another one and delete characters

我希望将旧网站重定向到新网站,URL 如下所示:https://test.fr/directory/homepage.html 在我的 .htaccess 文件中,我有:

RedirectPermanent / https://google.com/`

但它的作用是:https://google.com/directory/homepage.html

我想重定向到 https://google.com/ 并删除 .com/ 之后的所有内容,但我不知道该怎么做。

直接使用重写模块:

RewriteEngine on
Rewrite ^ https://google.com/ [R=301,END]

显然需要将重写模块加载到 http 服务器中。对于所有托管服务提供商来说,通常都是这种情况。

如果您只想在您的 http 主机中重定向特定的 URL,那么应该这样做:

RewriteEngine on
Rewrite ^/?directory/homepage\.html$ https://google.com/ [R=301,END]

您可以在分布式配置文件 (".htaccess") 中实施此类指令。不过,如果您有权访问它,您应该更喜欢实际的 http 服务器的主机配置。