Neil Reardon
Neil Reardon

Reputation: 65

Redirect url to another domain using .htaccess

I have the following in a .htaccess file:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

</IfModule>

# END WordPress

I have tried the following but it does not work:

RewriteRule ^this-url$ http://www.anotherdomain.com/ [NC,L,R=301]

Any idea how I can resolve this?

Regards,

Neil.

Upvotes: 0

Views: 28

Answers (2)

Croises
Croises

Reputation: 18671

It should work with your rule, but it must be placed before those concerning WordPress (Always redirect before rewriting):

RewriteEngine On
RewriteRule ^this-url$ http://www.anotherdomain.com/ [NC,L,R=301]

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Upvotes: 2

FileInputStream
FileInputStream

Reputation: 126

i'm using this code for my htacces to redirect to another website.

RewriteEngine On
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R=301,L]

That should work.

Upvotes: 0

Related Questions