简体   繁体   English

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

[英]Htaccess redirect URL to another one and delete characters

I want an old website to be redirect to the new one, the URL looks like this: https://test.fr/directory/homepage.html In my .htaccess file I have: I want an old website to be redirect to the new one, the URL looks like this: https://test.fr/directory/homepage.html In my .htaccess file I have:

RedirectPermanent / https://google.com/`

But what it does: https://google.com/directory/homepage.html但它的作用: https://google.com/directory/homepage.html

I'd like to redirect to https://google.com/ and delete everything after the .com/ but I have no idea how.我想重定向到https://google.com/并删除.com/之后的所有内容,但我不知道如何。

Just use the rewriting module:只需使用重写模块:

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

Obviously the rewriting module needs to be loaded into the http server for that.显然,需要将重写模块加载到 http 服务器中。 This usually is the case, certainly for all hosting providers.这通常是这种情况,当然适用于所有托管服务提供商。

If you only want to redirect that specific URL inside your http host, then that should do:如果您只想在 http 主机内重定向特定的 URL ,那么应该这样做:

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

You can implement such directives in a distributed configuration file (".htaccess").您可以在分布式配置文件(“.htaccess”)中实现此类指令。 You should prefer the actual http server's host configuration though, if you have access to that.不过,如果您有权访问,您应该更喜欢实际的 http 服务器的主机配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM