user2693017
user2693017

Reputation: 1860

RewriteCond/Rewrite Rule - Apache 2

at the moment I use these rewrite rules/conditions:

RewriteEngine On
RewriteRule ^/forum/.* https://mineyourmind.net/forum/$1 [R=301,L]
RewriteRule ^/contao/.* https://mineyourmind.net/contao/$1 [R=301,L]
RewriteCond %{REQUEST_URI} !^/forum 
RewriteCond %{REQUEST_URI} !^/contao
RewriteCond %{HTTP_HOST} ^(www\.)?mineyourmind\.de$ [NC]
RewriteRule (.*) https://mineyourmind.net/de%{REQUEST_URI} [R=301,L]

They work perfect and every rewrite should stay the same instead of one.

If you visit mineyourmind.de (the main/home site) I don´t wont it to redirect to mineyourmind.net/de. It should redirected to mineyourmind.net that the rewrite of the .net site can decide the language.

I couldn´t get this working, how would you manage this ?


Edit:

There is no problem with these rewrite rules and I use them in the apache site config. I just want that every which goes to mineyourmind.de (root url) is directed to mineyourmind.net and not to mineyourmind.net/de. All the other redirection should stay the same.

Edit2:

'' = all other sites (not root, not forum/, not contao/*)

Upvotes: 1

Views: 372

Answers (1)

anubhava
anubhava

Reputation: 784918

Try this code:

RewriteEngine On

RewriteRule ^/?((?:forum|contao).*)$ https://mineyourmind.net/$1 [R=301,L,NC]

RewriteCond %{HTTP_HOST} ^(www\.)?mineyourmind\.de$ [NC]
RewriteRule ^/?$ http://mineyourmind.net/ [R=301,L]

RewriteCond %{REQUEST_URI} !^/(contao|forum) [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?mineyourmind\.de$ [NC]
RewriteRule ^ https://mineyourmind.net/de%{REQUEST_URI} [R=301,L]

This will skip mineyourmind.de (the main/home site) to be redirected to mineyourmind.net because of use ^/?.+$ regex that makes sure that it is not home/root page.

Upvotes: 1

Related Questions