Htaccess rule for redirecting to .com


How can I redirect to https://www.mydoman.**com**/slug1/slug2 ?


What have you tried so far?

Hi @rpkamp

Ive tried:

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.co\.uk$ [NC]
RewriteRule ^(.*)$$1 [R=301,L]

Which I got from this

But that has no effect. I thought it may be because it was conflicting with something else in my htaccess file, so I removed everything else in my htaccess file, but it still didnt do anything. Very odd.

I don’t know if this is any help:

I haven’t tried that particular scenario, but I’ve found that article helpful in the past.

Hmmm, none of those examples will work. I tried the specific one you linked to, but it just results in an infinite loop.

However, I did try a variation

RedirectRule 301*)$1

But that didnt work either. :unamused:

1 Like

OK, Ive got it working!

Ive used

  RewriteEngine On
  RewriteCond %{HTTP_HOST} ^$ [OR]
  RewriteCond %{HTTP_HOST} ^$
  RewriteRule (.*)$$1 [R=301,L]

No idea why that works and the others didnt. I will investigate further.

Thanks all for your help.


This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.