During my .htaccess file I've defined the next rule to create my register page URL as http://example.com/register/

RewriteRule register/ /register.php

The above mentioned rule is perfectly fine however i can access my register page from http://example.com/register/ in addition to from http://example.com/register.php.

I'm not going that user will have the ability to access the URL from http://example.com/register.php URL, can there be any RULE that we can define inshtaccess to prevent execution of register.php URL or just redirect any direct register.php request to /register/

If you're carrying this out to prevent getting multiple links towards the same content, you can just avoid using "register.php" anywhere in your page. I believe no internet search engine will "guess" for any certain file type and when you will find no security concerns you're safe and sound, because for me no user will connect to this file either. However if you wish to be sure just reroute all of your functionality with an index.php via one line inside your .htaccess that ought to go within your www-root directory:

RewriteEngine on
RewriteRule ^(.*?)$ index.php?file=$1

Inside your index.php after that you can simply determine which function/file to invoke by wearing down and checking the $_GET["file"] parameter. To create 100% certain no-one can access your register.php file directly just move it (and all sorts of your others) to some separate directory and can include b .htaccess file using the following line:

DENY from all

You will find a few other available choices to avoid immediate access. Just define() a flexible somewhere inside your index.php and towards the top of your register.php just put

defined('access') or die('Intruder alert!');

at the very top. One other way would be to be truthful and just tell search engines like google that the content continues to be moved which they no more should make use of the old link:

header("Status: 301"); /* Content moved permanently */
header("Location: http://yourserver/Register/");
exit;

Update

Only one more factor that entered my thoughts, you may also check $_SERVER["REQUEST_URI"], if the user attached any ".php" and act accordingly by either denying access completely or simply redirecting towards the new location.

Do this.

RewriteCond %{REQUEST_FILENAME} ^register\.php$ [NC]
RewriteRule ^/register register.php

Or this

Redirect register.php /register

Disregarding the consumer-experience part, you are able to implement the new rel=canonical link to work through the search engines like google.

Although, for this situation you need to most likely only use a 301 redirect from /register.php to /register/

In register.php

if ( stristr( $_SERVER['REQUEST_URI'], '.php' ) )
{
    header ('HTTP/1.1 301 Moved Permanently');
    header ('Location: /register');
}

If you wish to completely block /register.php by utilizing mod_rewrite, make use of a variant of SleepyCod's answer:

RewriteCond %{REQUEST_FILENAME} register\.php [NC]
RewriteCond %{IS_SUBREQ} false
RewriteRule .* - [F,L]

Explanation:

  • [NC]: Helps make the condition situation-insensitive, just just in case you are on the home windows box.
  • Condition 1: The asked for filename is 'register.php', and
  • Condition 2: The request is no subrequest (this will be significant, since every new round through RewriteRules really produces subrequests).
  • Rule: basically do nothing at all
  • Flags: [F]: Send an 403 Forbidden header, [L]: This is actually the last rule to use, skip all following rewrite rules

Spinning properly is definitely an art alone. It is best to carefully read http://httpd.apache.org/docs/2.2/rewrite/.

Cheers,