Forum Moderators: phranque
# Externally redirect to remove additional URL-path info following
# "/index.php" e.g. "GET /index.php/<[i]additional-directory-and/or-filepath[/i]>"
RewriteRule ^index\.php/(.*)$ http://www.example.com/$1 [R=301,L]
#
# Externally redirect direct client requests for old dynamic URLs to new 'SE friendly' URLs
# (e.g. redirect requests for "/?product=widget" to "www.example.com/product/widget" or
# redirect requests for "/index.php?product=widget" to "www.example.com/product/widget")
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /(index\.php)?\?page=2&(application)=([^&\ ]*)\ HTTP/ [NC,OR]
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /(index\.php)?\?page=3&(product)=([^&\ ]*)\ HTTP/ [NC]
RewriteRule ^(index\.php)?$ http://www.example.com/%2/%3? [R=301,L]
#
# Externally redirect direct client requests for "/<any-directory>/index.php" to "/<any_directory>/"
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*index\.php([?#][^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+/)*)index\.php$ http://www.example.com/$1 [R=301,L]
#
# Last (least-specific) redirect: Redirect all non-blank non-canonical hostname requests to canonical hostname
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
#
# Internally rewrite SE-friendly URLs to script filepath+query
RewriteRule ^(application)/(.+)$ /index.php?page=2&$1=$2 [L]
RewriteRule ^(product)/(.+)$ /index.php/?page=3&$1=$2 [L]
Redirect /A/B.php http://www.example.com/C/D.php Redirect /web_page http://www.example.com/web-page
Redirect 301 /A/1028/B_C_D.php http://www.example.com/A/1028/E-F-G.php?
Redirect /A/1028/B_C_D.php http://www.example.com/A/1028/E-F-G.php? [R=301,L]
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
$HyphenatedURL=str_replace("_", "-", $_SERVER['REQUEST_URI']);
if ($HyphenatedURL != $_SERVER['REQUEST_URI'])
{
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://{$_SERVER['HTTP_HOST']}{$HyphenatedURL}" );
}