redirect a domain extension to a subdirectory

I am trying to create a permanent htaccess redirect (301) from all my domain extensions into the appropriate subdirectories. The “rules” are as follow:

Redirect belgian website to its subdirectory on the main website:

Read More

from: www.example.be

to: www.example.com/befr/

Of course I would like to preserve the url parameters (if any) of the “from”. Globaly, if someone entered the first url it should redirect to the second url (langage subdirectory in the main website).

I’m using wordpress and I’m hosting on a plesk I’ve read many things here but I’m stuck, thank you very much in advance for your help


PS: I’ve tried that but it doesn’t work

RewriteCond %{HTTP_HOST} ^(www.)?example.be$ [NC]
RewriteRule ^(.*) http://www.example.com/befr/$1 [L,R]

Related posts

Leave a Reply

1 comment

  1. After reading your question, your code should be working (with informations you gave).
    If it’s not, here are some points to check:

    1. Make sure mod_rewrite is enabled and htaccess can be executed (Apache config).

    2. Your htaccess has to be in root folder (where example.be is forwarded).

    3. About your htaccess’ code:

    • since you’re using WordPress, make sure your rule is on top of other rules
    • don’t forget to escape . (second one) in RewriteCond (otherwise it doesn’t mean the same) even if it works that way
    • replace R flag (302 by default) by R=301 if you want a 301 redirect

    Your code now looks like this

    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} ^(www.)?example.be$ [NC]
    RewriteRule ^(.*)$ http://www.example.com/befr/$1 [R=301,L]
    
    # your other rules (and WordPress' default rule) here