-1

I´m trying to redirect with rewrite rules in Apache .htaccess. I want to redirect 360invest.pl to 360investment.pl.

But I want one more address on the server which I do NOT want to be redirected. If somebody tries 360invest.pl/bezrzecze it should not redirect to 360investment.pl.

I used this code:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^360invest.pl/bezrzecze$ [NC]
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [OR,NC]
RewriteCond %{HTTP_HOST} ^360invest.pl$ [NC]
RewriteRule ^ http://www.360investment.pl%{REQUEST_URI} [L,R=301]

This works only if you try www.360invest.pl/bezrzecze. It doesn't work if you try http://360invest.pl/bezrzecze.

In addition if you click any link on the website (www.360invest.pl/bezrzecze) it will redirect you to www.360investment.pl - it should not.

I'm not sure what I'm missing here. Thank you for your help.

Maciej
  • 13
  • 1
  • 5

1 Answers1

0

What you are doing is really messy. The first condition does not make sense, because "360invest.pl/bezrzecze" is not a domain name. It is a domain name and a path. The following conditions with [OR] flags make no sense to me.

Think about what you want to accomplish. Start with the general case, then list your exceptions:

  • If someone goes to 360invest.pl you want to redirect all urls to 360investment.pl
  • unless someone goes to the path bezrzecze

The first part is the rule. The second part is a condition that has to be met

RewriteCond %{REQUEST_URI} !^/bezrzecze
RewriteRule ^ http://www.360investment.pl%{REQUEST_URI} [L,R]
Sumurai8
  • 20,333
  • 11
  • 66
  • 100
  • It still doesn't work. Please give me the whole code. – Maciej Jul 09 '17 at 15:02
  • Define "doesn't work". This is all you need except for the `RewriteEngine on` directive. – Sumurai8 Jul 09 '17 at 15:10
  • If you click something on the website an error occurs. – Maciej Jul 09 '17 at 20:20
  • Are both sites run on the same server from the same directory? What kind of error do you get? Do you get an internal server error, or does it complain about infinite redirects? – Sumurai8 Jul 10 '17 at 06:17
  • That websites are in different directories but on the same server. It complain about infinite redirects. – Maciej Jul 10 '17 at 10:39
  • Please press F12 in your browser, go to the network tab, preserve the log and go to `http://360invest.pl/url-you-have-not-tested-with-before`. Please inspect the urls the browser redirects too. Please verify that you only see 302 redirects. Please make sure that the .htaccess file you are using is in the Document root of 360invest.pl and that the document root of 360investment.pl is not a subdirectory of the document root of 360invest.pl. – Sumurai8 Jul 10 '17 at 16:47
  • I see only 302 redirects but I've noticed there are one more htacces in path bezrzecze `# BEGIN WordPress RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] # END WordPress` – Maciej Jul 12 '17 at 15:37
  • Ah, good old Wordpress. See [this answer](https://stackoverflow.com/questions/25362629/url-rewriting-not-working-with-wordpress-unless-using-r/25385434#25385434) for more information. – Sumurai8 Jul 12 '17 at 16:40
  • Okay I have read that post and I made changes but something is missing. If you click on some links it still redirects to 360investment.pl It's crazy. – Maciej Jul 12 '17 at 17:12