More tips on .htaccess

in Articles, Facebook / No Comments

Recent days I got an issue with Facebook Application, In that application used .htaccess to redirect the urls, If we want to use this app then we should have secured url i.e. ‘https’, Before purchase the SSL for our domain. We can check our app by changing the security permission in https://www.facebook.com/settings?tab=security , we can see the flow to check that how can we change that.

More tips on .htaccess by Anil Kumar Panigrahi

More tips on .htaccess by Anil Kumar Panigrahi

Change the settings in Facebook

Screen #1

More tips on .htaccess - Facebook Security Settings Screen  - by Anil Kumar Panigrahi

More tips on .htaccess – Facebook Security Settings Screen – by Anil Kumar Panigrahi

Screen #2

More tips on .htaccess - Facebook Security Settings Screen  - by Anil Kumar Panigrahi

More tips on .htaccess – Facebook Security Settings Screen – by Anil Kumar Panigrahi

After changing that we can access the our page app without ‘https’, In this way we can approach our application will work. If you access the application with ‘https’ then you will get blank or error will get.
After purchase the SSL certificate for your site and we can force to get the website with ‘https’ by adding below in your .htaccess file

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTPS} !^on$
    RewriteRule (.*) https://%{HTTP_HOST}/$1 [R=301,L]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>

By adding above code in your website, we will force to get/redirect with ‘https’. Then will effect to your Facebook application too. If you change the security settings to disable, then your application we will get the Facebook page id.

$FBsignedRequest = $Facebook->getSignedRequest();

In the above code $FBsignedRequest will get the NULL.

because in the Facebook application, url will redirect to http://domain.com/fbapp/ to https://domain.com/fbapp/ then we loose the posted values i.e. getSignedRequest which from Facebook API, After research on the same issue about 4 hours, finally I got solutions for it.

Add the below code for your .htaccess file

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTPS} !^on$
    RewriteRule (.*) https://%{HTTP_HOST}/$1 [R=307,L]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>

In this also URL will redirect but with posted values i.e. getSignedRequest

Recently my friend Srinivas Tamada posted regarding Create Custom Facebook Application and regarding .htaccess Htaccess File Tutorial and Tips

This post is extensions to those posts.

With more than 9 years experience in PHP and Founder of Anil Labs, a blog for PHP and related posts. contributed posts regarding CodeIgniter, CakePHP and Learn PHP online ... Contact : [email protected]

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>