And so do rewritten my ugly php Hyperlink to something more attractive:

RewriteEngine On
RewriteRule ^main/photo([^/\.]+)/?.html$ main/details.php?gid=$2pid=$1

However, now I wish to pressure anybody who would go to

to redirect to


I've attempted the next RewriteCond:

RewriteCond %{REQUEST_URI} ^/main/details\.php [NC]
RewriteRule ^main/details.php?gid=(.*)&pid=(.*)$1.html [R=301,L]

But that did not work. Any ideas?

You have to consider the request line to find out when the current request URI may be the original. Furthermore you should utilize the RewriteCond directive to check the query from the URI:

RewriteCond %{THE_REQUEST} ^GET\ /main/details\.php
RewriteCond %{QUERY_STRING} ^(([^&]*&)*)pid=([0-9]+)(&.*)?$
RewriteRule ^main/details\.php$ /main/photo%3.html? [L,R=301]