Forum Moderators: phranque
RewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?username=$1
RewriteEngine On
RewriteCond %{SERVER_PORT}s ^(443(s)|[0-9]+s)$
RewriteCond %{REQUEST_URI} ^profile.php?username=$1 [NC]
RewriteRule ^(.+)$ http%2://%{HTTP_HOST}/([a-zA-Z0-9_-]+) [R,L]
# HTTPS 301 redirect on login.php and signup.php
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteCond $1 !\.(gif|jpg|png|ico|css|js)$
RewriteRule ^(test.php|login.php|signup.php)$ https://%{HTTP_HOST}/$1 [R=301,L]
# HTTP 301 redirect
RewriteCond %{SERVER_PORT} ^443$
RewriteCond %{REQUEST_URI} !^/(test.php|login.php|signup.php|profile.php)$
RewriteCond %{REQUEST_URI} !\.(gif|jpg|png|ico|css|js)$
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTPS} =on
RewriteRule ^(.+)$ - [env=ps:https] [L]
RewriteCond %{HTTPS} !=on
RewriteRule ^(.+)$ - [env=ps:http] [L]
RewriteCond %{THE_REQUEST} ^[A-Z]\ /profile\.php\?username=([^&]+)\ HTTP/
RewriteRule ^profile\.php$ %{ENV:ps}://www.example.com/%1? [R=301,L]
RewriteRule ^([A-Za-z0-9_]+)/?$ profile.php?username=$1 [L]
RewriteCond %{HTTPS} =on
RewriteRule ^(.+)$ - [env=ps:https] [L]
RewriteCond %{HTTPS} !=on
RewriteRule ^(.+)$ - [env=ps:http] [L]
RewriteCond %{THE_REQUEST} ^[A-Za-z0-9_-]\ /profile\.php\?username=([^&]+)\ HTTP/
RewriteRule ^profile\.php$ %{ENV:ps}://www.mydomain.tld/%1? [R=301,L]
RewriteRule ^([A-Za-z0-9_-]+)/?$ profile.php?username=$1 [L]
RewriteCond %{REQUEST_URI} ^profile.php?username=$1 [NC]
RewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?username=$1
# HTTP 301 redirect
RewriteCond %{SERVER_PORT} ^443$
RewriteCond %{REQUEST_URI} !^/(test.php|login.php|signup.php)$
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{THE_REQUEST} ^[a-zA-Z0-9_-]+\ /profile\.php\?username=([^&]+)\ HTTP/
RewriteRule ^profile\.php$ http://www.mydomain.co/%1? [R=301,L]
RewriteRule ^([a-z0-9_]+)/?$ profile.php?username=$1 [NC,L]
/? on the end of the Regex Pattern of the rewrite promotes Duplicate Content. Set up a preceding redirect to redirect from with-slash to without-slash for page URLs to eliminate this problem. THE_REQUEST will be GET or POST or HEAD, etc, followed by a space then a forward slash. Match this with ^[A-Z]{3,9}\ / here. [NC] allows aNyCase and so your PHP script should check the casing of any request. If the casing is incorrect it is the PHP script that should issue the HTTP 404 status and then send the HTML page containing the human-readable error message.
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /profile\.php\?username=([^&]+)\ HTTP/
RewriteRule ^profile\.php$ http://dev.datingpatch.com/%1? [R=301,L]
RewriteRule ^([a-zA-Z0-9_]+)$ profile.php?username=$1 [NC,L]