Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Website Redirect If Website Matches

Featured Replies

Hello.

 

I am currently trying out a new few things whilst making my website but I have run into a problem I am hoping someone could assist me with.

 

I have a website at www.abc.com which is the main domain but I want to be able to make it redirect to www.abc.com/xyz if they come from http://www.facebook.com.

 

So in other words my website is www.abc.com which is the domain for public users but if they come from Facebook I want it to redirect to a folder on my website which is customised for Facebook if that makes sense. I have tried using HTACCESS but can't get it to work.

 

This is what I have tried, I am still learning so code may be wrong:

 

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.abc.co.uk$ [NC]    
RewriteCond %{REQUEST_URI} ^/facebook$    
RewriteRule ^/?a/(.*)$ https://www.facebook.com/$1 [R=301,L]

 

  • Author

Please can someone help. Even if you can point me into the right direction of finding it out myself it would be much appreciated. Am I supposed to do it in HTACCESS?

  • Author

I managed to get it to work using:

 

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^https://www.facebook.com/ [NC]
RewriteRule ^ http://www.buy-sell-today.co.uk/facebook/index.html [L,R]

But it won't actually load up the webiste: take a look at the screenshot here: http://puu.sh/5tRPo.jpg

Edited by oChapperZo

Try removing the http

 

RewriteEngine On
RewriteCond %{HTTP_REFERER} !www.facebook.com/groups/1387722168128069 [NC]
RewriteRule ^/?facebook/$ www.buy-sell-today.co.uk/ [L,R]

but I'm only guessing

  • Author

Still don't seem to be working - I'm starting to fix if it's easier to create a directory and on Facebook add that URL instead but I would prefer just having http://www.buy-sell-today.co.uk and understand if the link comes from Facebook it loads up the Facebook side of my website.

You could place this javascript in your document

<script>
    if (document.referrer.indexOf('http://www.facebook.com./') == 0 ) {
    		location.href = 'www.abc.com/xyz';
    }
</script>

It's a dirty fix but it should work for most users

  • Author

I will try and use this code and see what happens, I will get back to you.

 

Why would this technique be "dirty". I guess the correct way is to use HTACCESS?

I will try and use this code and see what happens, I will get back to you.

 

Why would this technique be "dirty". I guess the correct way is to use HTACCESS?

The reason I call it "dirty" is because it's done with javascript and the link could therefore mislead search engines trying to follow it (and other non-js-users). I'm sure it's possible to create an identical script with PHP (or whatever serverside language you are using) I just don't know the exact syntax. A serverside or HTACCESS redirection or would be a cleaner solution and ensure that all users gets redirected regardless if they have javascript enabled or not.

 

Let me just add: I don't fear you will get a google "penalty" for using js redirects (Unless maybe if you redirect users to some totally unrelated url)

Edited by Nillervision

^^ Same question here. Using the HTACCESS seems preferable to javascript in case it is disabled. This is my best guess:

 

RewriteEngine on
 RewriteCond %{HTTP_REFERER} ^http://(www\.)?facebook\.com
 RewriteRule ^$ /facebook/index.html [L]

If it is for Analytics reasons it would probably be better to configure your analytics.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.