0

Im new here at stack overflow, and don't have a lot of coding experience, and was thinking that my chances of finding a coding genius to help me, must be biggest in here.

So here it goes:

I have this url: https://www.domain1/numbers/variables

And i want to redirect that to https://www.domain2/pages/hello

I want to redirect everything that is: www.domain1/numbers/
...no matter which variables that comes along with it.

And the page i want to redirect to, is always the same.

I hope somebody can help, thanks.

Best regards Nicolai

  • Possible duplicate of [.htaccess redirect all pages to new domain](https://stackoverflow.com/questions/1945568/htaccess-redirect-all-pages-to-new-domain) – Marvin Fischer Jul 23 '18 at 12:51

1 Answers1

0

Try using this in your .htaccess:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^ (www\.)?domain1.com/$1 [NC]
RewriteRule ^(.*)$ https://www.domain2.com/pages/hello [R=301,L]

The condition grabs both https://domain1.com/anything and https://www.domain1.com/anything and redirects them to https://www.domain2.com/pages/hello by using R=301 which is a permanent redirection. While testing you might want to change that to R=302 which is a temporary redirect.

You can see this rule working here: https://htaccess.madewithlove.be?share=6c02aa2d-ff08-5d45-b07e-2cad294a329f

Make sure you clear your cache before testing this.

EDIT

See code below based on your specific specifications based in comment:

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteCond %{HTTP_HOST} ^ (www\.)?skip.com/$1 [NC] 
RewriteRule ^(.*)$ https://kapsio.com/pages/velkommen-til-kapsio [R=301,L] 
</IfModule>
Joe
  • 4,877
  • 5
  • 30
  • 51
  • Hi thanks for your answer. I need to redirect this: https://skip.dk/fmemailverification/variables to: https://www.kapsio.com/pages/velkommen-til-kapsio So only skip.dk/fmemilverification and no other skip.dk/pages or skip.dk/blogpost Is this correct? # BEGIN WordPress RewriteEngine On RewriteCond %{HTTP_HOST} ^ (www\.)?skip.com/$1 [NC] RewriteRule ^(.*)$ https://www.kapsio.com/pages/velkommen-til-kapsio [R=301,L] # END WordPress – Nicolai Ibsen Jul 23 '18 at 13:48
  • Almost. See my edit in my answer, you had a small mistake which I've corrected. You were missing `https://` in the RewriteRule. That needs to be there in order for it to work, otherwise it won't switch domains. – Joe Jul 23 '18 at 13:54
  • Ok. so i added in what you put in the edit, and got a 500 internal server error I change the .htacces file from this: # BEGIN WordPress RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] # END WordPress – Nicolai Ibsen Jul 23 '18 at 14:16
  • To this: RewriteEngine On RewriteCond %{HTTP_HOST} ^ (www\.)?skip.com/$1 [NC] RewriteRule ^(.*)$ https://kapsio.com/pages/velkommen-til-kapsio [R=301,L] Why did i get a 500 internal server error? – Nicolai Ibsen Jul 23 '18 at 14:17
  • Don't remove the first bit. I never said to do that, if it is a WordPress website then you need to leave the original bit in there. – Joe Jul 23 '18 at 14:18
  • My bad. now i done this and still get error 500 # BEGIN WordPress RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{HTTP_HOST} ^ (www\.)?skip.com/$1 [NC] RewriteRule ^(.*)$ https://kapsio.com/pages/velkommen-til-kapsio [R=301,L] # END WordPress – Nicolai Ibsen Jul 23 '18 at 14:26