I had a hard time finding a solution to redirect only certain files from HTTP to the secure HTTPS. I found all kinds of ways to redirect the entire site to HTTPS but none for specific pages only. After a few hours tinkering I found a solution using the following code in a .htaccess file:

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^example.com [nc]
rewriterule ^(.*)$ http://www.example.com/$1 [r=301,nc]
 
rewritecond %{SERVER_PORT} !^443$
rewriterule ^filename\.php(.*)$ https://www.example.com/filename.php$1 [r=301]

The first part of the code redirects example.com to www.example.com as noted in an earlier post, “301″ Redirects for SEO. The second part then redirects a specific file (filename.php) from http to https. Thus the individual file “filename.php” can only be accesses using a SSL connection.

It is good to share: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Furl
  • Ma.gnolia
  • NewsVine
  • Reddit
  • Spurl
  • StumbleUpon
  • Technorati

Categories: Website Design ~ Tags: , , , , ~ Trackback

Leave a Reply

.htaccess accessibility Apple articles browser bugs CSS domain names ecommerce email ems eps fonts HTML http https IE Internet Explorer interview Mac menu PayPal plugins redirects Safari SEO spam SSL tools web standards website design Windows WordPress