For profile.php

# Rewrite profile URLs
#   Input:  profile/NAME/
#   Output: profile.php?id=NAME
RewriteRule ^profile/(\w+)/?$ profile.php?id=$1

# Prevent Direct Access to profile.php
# THE_REQUEST is the whole original request,
# if the original request has "profile.php"
# send back a 403 Forbidden Warning
RewriteCond %{THE_REQUEST} profile\.php
RewriteRule ^profile\.php - [F]
Profile.php
Incoming Match Capture Outgoing Result
profile.php?id=joe Yes (#2)   profile.php?id=joe Forbidden
profile/joe Yes (#1) joe profile.php?id=joe Good
profile/joe/ Yes (#1) joe profile.php?id=joe Good
profile/joe/x No   profile/joe/x Fail

Back