0

Hi

I have a twiiter user linking to a specific page on my website which I would like to redirect to my home page. From the internet I have found and adapted the following code

RewriteCond %{HTTP_REFERER} (twitter.com) [NC]
RewriteRule myloginpage.php http://mywebsite.org/index.html [R,L,NC]

Unfortunately this doesn't do anything.

Can anyone tell me if there is an error in the code please?

Thank you

2
Contributors
6
Replies
23
Views
2 Years
Discussion Span
Last Post by nibbler
0

Pretty much every rewrite I have seen uses some form of regex to capture the condition. (twitter.com) will look for the exact string "(twitter.com)" as far as I understand it.

Maybe try using a simple regex to meet your needs -
RewriteCond %{HTTP_REFERER} .twitter.com.$ [NC]

Also, while I don't ultimately know the needs of your rule, Im guessing your RewriteRule will need to be modified some, as I think you are going to end up having a url that looks something like http://mywebsite.org/http://mysebsite.org/index.html assuming that the incoming uri is http://mywebsite.org/myloginpage.php

If that is the case, simply change
RewriteRule myloginpage.php http://mywebsite.org/index.html [R,L,NC]
to
RewriteRule ^(.*)$ http://mywebsite.org/index.html [R,L,NC]

and that may solve your issue...

Edited by ryantroop

0

So I re-read the above and the editor formatted something incorrectly above.

It should be:
RewriteCond %{HTTP_REFERER} *.twitter.com*.$ [NC]

0

Many thanks for the help with this, much appreciated.

Does the rewrite rule you've provided ^(.*)$ mean that any link from the twitter account will be redirected to my home page? That's not quite what I'm after, It is only links to the login.php page that I want to redirect, I'm happy with links to other pages

0

Yes, you are correct.

So instead, you could do something like
RewriteRule *.myloginpage.php$ http://www.mywebsite.org/index.html [R,L,NC]

Truth be told, I would have to tinker with it and figure it out myself, as I rarely have to do htaccess files.. you know.. do it once and you're usually done :-/

What I think the above will do is capture any URI that ends with myloginpage.php and redirect to your index.html instead.

Edited by ryantroop

0

Thanks again

My first attempt resulted in a 500 Internal Server Error but at least you've given me something to work on

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.