Search code examples
apache.htaccesshttp-redirect

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.


Solution

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