简体   繁体   中英

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:

RedirectPermanent / https://google.com/`

But what it does: 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.

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. 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:

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

You can implement such directives in a distributed configuration file (".htaccess"). You should prefer the actual http server's host configuration though, if you have access to that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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