WordPress.org

Ready to get started?Download WordPress

Forums

facebook integration (11 posts)

  1. omelani
    Member
    Posted 1 year ago #

    This is a simple yet useful question if anyone can answer, I wanted my wordpress url page to be automaticaly redirected to my facebook page and all links of post pages, likes and shares send tweet within my wordpress page would be redirected to a coressponding link to my facebook page for example:
    when i go to my wordpress page: "www.example.com" I would go to "https://www.facebook.com/example/app_12345678910111213"
    and when i go to a post of my page "www.example.com/Helloworld" it would go to
    "https://www.facebook.com/example?sk=app_12345678910111213&app_data=Helloworld", this would affect all links including for example when i have a like button (jetpack) when I share or like a post it would direct to a corresponding link to my facebook page.

    Is there a plugin or workaround for these, It would open a whole lot of possibilities.

  2. bcworkz
    Member
    Posted 1 year ago #

    I must be missing something. If all your content is on facebook, why use WordPress at all? A rewrite structure in the .htaccess file of example.com would accomplish what you want to do, the way I understand it.

  3. omelani
    Member
    Posted 1 year ago #

    wordpress is a great content management system with a wide array of plugins for forms map gallery you could easily create a contest that is great for engagement, anyway how can I do that with .htaccess that every link on my wordpress would affect my facebook fan page url too, my wordpress page is inside a canvas?

  4. omelani
    Member
    Posted 1 year ago #

    I have here for example a store locator, I want user to share them on facebook but I dont want them to go to my wordpress site I want them to go to my canvas url with the specific map location url they have selected but the problem is everytime I select a location it does not change the facebook page url dynamically, is there a way to do this on wordpress to affect the facebook page url.

    https://www.facebook.com/extrastores/app_208195102528120

  5. bcworkz
    Member
    Posted 1 year ago #

    Yes, I was missing something... where your content actually was. So keep WP :)

    Still, if every permalink gets passed to your facebook app as an url parameter, an .htaccess rewrite should do the job. Unfortunately, .htaccess is tricky, one silly mistake and your entire site goes down, so I can't help with any actual code. No doubt there will be details to iron out, and there could be a fatal flaw I'm not seeing, but worth a try I think.

    One detail for starters is you'll need a rule to not rewrite /wp-admin/ requests so you can access your WP site. There's no doubt more.

    FWIW, something similar can be done using the WP Rewrite API, but .htaccess would be much more efficient. Good luck!

  6. omelani
    Member
    Posted 1 year ago #

    thanks for the reply, yup htaccess can redirect my pages to my facebook page, but It would just specify one url https://www.facebook.com/extrastores/app_208195102528120, what I want is when I choose a location in my wordpress the canvas page link would also change to https://www.facebook.com/extrastores/app_208195102528120/location/ I do not know if this is htaccess or a facebook api because I really cant find someone who have dine this, but this could open a whole lot of possibilities we could use wordpress to create photo contest, quiz, survey, as a faceboook app...if there is a way to do this.

  7. john012
    Member
    Posted 1 year ago #

    Did you try to use facebook plugin?
    I have one plugin here

  8. omelani
    Member
    Posted 1 year ago #

    yes I have tried it before but when I share a post it links back to my wordpress site, I want it to link back to my facebook app page showing the post I shared. I want my wordpress site to behave like an app.

  9. bcworkz
    Member
    Posted 1 year ago #

    The WP links will still point to the same local WP links, but when the link is clicked in FB, the request is sent to your server, which is intercepted by .htaccess. The rewrite code can extract arbitrary permalink content by position in the request url by using regexp and pass that permalink data to your FB app as url parameters.

    I know little of FB apps, I was assuming from your first example it could take such url parameters and load the correct page.

    Which brings up another detail. The rewrite rule will need to except requests from FB or else it'll never be able to load your content!

  10. omelani
    Member
    Posted 1 year ago #

    now this is all alien to me, if you could explain how to do it on .htaccess, my app is inside an iframe (canvas page) if there is a way to change the url of the facebook page that would reflect the inner(iframe canvas) page it would be great because right now I am really bumped, the closest plugin I have tried is wpbook but it uses apps.facebook.com not the canvas page tab and it is realy hard to style(theme).

  11. bcworkz
    Member
    Posted 1 year ago #

    You can only alter FB URLs to the extent FB gives you the ability to alter them. AFAIK, you have little to no control at all.

    OTOH, you can play all sorts of games with URLs on your own server. This is a general example of the rewrite I'm talking about. It is likely flawed in several details and untested, so you should do some more research into the proper syntax before putting it on your server. As I mentioned, one error can bring down your whole site, so keep sequential backups of your various attempts so you can revert to any previously working version. This is just intended for illustrating the basic form.

    <IfModule mod_rewrite.c>
    	RewriteEngine On
    	RewriteBase /
    	RewriteCond %{REQUEST_METHOD} GET
    	# Enter your current ISP IP ranges for admin access
    	RewriteCond %{REMOTE_ADDR} !^64\.156\.92\.
    	RewriteCond %{REMOTE_ADDR} !^128\.32\.61\.
    	RewriteCond %{HTTP_REFERER} !^https?\://w*\.?facebook.com/extrastores
    	RewriteRule yourdomain.com/(.*)/? http://facebook.com/extrastores/app_208195102528120/$1/ [L]
    </IfModule>

    This needs to go above the WP portion in .htaccess or WP will grab the request before this one gets a chance. The IF block is so nothing breaks if the rewrite module isn't available. The On directive indicates a new set of conditions and rules. The base directive indicates relative urls are relative to root. The remaining conditions must be met for the rule to be applied. The request must thus be the GET type, POSTs go through to WP.

    The REMOTE_ADDR lines must be changes to the IPs you use to administer WP. IPs have 4 numbers separated by dots. I show 3 numbers to allow for dynamic IP allocation used by most ISPs. For large ISPs, there may be only be the first 2 numbers in common for the entire range, so then just use 2 numbers. You may get assigned an IP from a number of blocks, thus the second line to cover a different range. Add as many lines as needed. The drawback here is if anyone visiting uses the same ISP, they will be taken to your home WP site instead of FB. Of course, if you have a static IP, use that and forget the extra lines etc. If the visitors using the same ISP is a big issue for you and you are on dynamic assignment, you would have to determine your IP every time you want to administer WP and update the .htaccess file with your current IP.

    The condition syntax is regexp. The exclamation mark means NOT, meaning redirect everyone but those with a matching condition. The backslash is an escape char meaning the next char is a literal and not a special regexp char. The caret means the next char must be at the beginning of the data field. Question marks mean the preceding char is optional. The dot char matches any other char. The asterisk means match the precedeing char any number of times. Parenthesis add anything matched inside to a forward reference. (more on references later)

    Each condition is logically ANDed with the next, unless the line ends with [OR]. The facebook line allows GET requests from your facebook.com account through to get the actual content. So all the conditions together mean rewrite any GET request that is not from your IP and not from your facebook account.

    This is the cool part that gets any URL redirected with the proper parameter. The first part of the final rule matches the first permalink segment after your domain as a forward reference. Right now, everything after that is ignored, but can be extended. The second part of the rule redirects to your facebook app, the $1 portion gets replaced with the first forward reference. If you extend the first part, you reference each subsequent with $2, $3, etc. The [L] means stop more .htaccess processing and do the redirect immediately.

    In summary, a request of domain.com/location/ that is a GET and not from your ISP and not from facebook will be sent to http://facebook.com/extrastores/app_208195102528120/location/. Same with domain.com/location2/. It gets sent to http://facebook.com/extrastores/app_208195102528120/location2/ and so on.

Topic Closed

This topic has been closed to new replies.

About this Topic