Search code examples
phpapache.htaccesshttp-redirectmod-rewrite

htaccess redirect subdomain to new domain WITHOUT subdomain


Almost there:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^forums\.resistance\.tk  [NC]
RewriteRule ^(.*) https://www.libertaire.net/$1 [L,R=301]

This will redirect

http://forums.resistance.tk/message.php?t=7751

to

https://www.libertaire.net/forums/message.php?t=7758

but I want

https://www.libertaire.net/message.php?t=7758

How can I achieve this?


Solution

  • In order to remove /forums/ while redirecting use this rule:

    RewriteEngine on
    
    RewriteCond %{HTTP_HOST} ^forums\.resistance\.tk$  [NC]
    RewriteRule ^forums(/.*)?$ https://www.libertaire.net$1 [L,R=301,NC]
    

    Make sure to clear your browser cache before testing this.