Forum Moderators: phranque
# Define directory index page filepath
# Optional -- may already be previously-defined by server confiog, and therefore not required
DirectoryIndex index.php
#
# Enable rewriting engine
RewriteEngine on
#
# Externally redirect direct client requests for /forum/index.php to forums.example.com
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /forum/index.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^forum/index\.php$ http://forums.example.com/ [R=301,L]
#
# Externally redirect direct client requests for /index.php in any
# directory to "/" in that same directory (for the forums subdomain)
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*/index.php([#?][^\ ]*)?\ HTTP/
RewriteCond %{HTTP_HOST} ^([^.]\.)?forums\.([^.]\.)?mydomain\.us
RewriteRule ^(([^/]+/)*)index\.php$ http://forums.example.com/$1 [R=301,L]
#
# Externally redirect direct client requests for /index.php in any
# directory to "/" in that same directory (for the main domain)
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*/index.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+/)*)index\.php$ http://www.example.com/$1 [R=301,L]
#
# Externally redirect direct client requests for /forum/<anything> to
# forums.example.com/<anything> (applies to all requested domains)
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /forum/[^\ ]*\ HTTP/
RewriteRule ^forum/(.+)$ http://forums.example.com/$1 [R=301,L]
#
# Externally redirect non-canonical forum subdomain requests to canonical forum subdomain
RewriteCond %{HTTP_HOST} !^(forums\.example\.com)?$
RewriteCond %{HTTP_HOST} ^([^.]\.)?forums\.([^.]\.)?mydomain\.us
RewriteRule ^(.*)$ http://forums.example.com/$1 [R=301,L]
#
# Externally redirect other non-canonical domain requests to canonical main domain
RewriteCond %{HTTP_HOST} !^((forums|www)\.example\.com)?$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
#
# Internally rewrite requests for forums subdomain to /forum subdirectory filepath
RewriteCond $1 !^forum/
RewriteCond %{HTTP_HOST} ^forum\.example.com
RewriteRule ^(.*)$ /forum/$1 [L]
Further, search engines will take a 301 redirect as a request to discard the original URL and use only the new one for search listings and ranking.
ErrorDocument 404 /error404.php # Externally redirect requests for forums subdomain to /forum subdirectory
RewriteCond %{HTTP_HOST} ^forums\.example\.us
RewriteRule ^(forum/)?(.*)$ http://www.example.com/forum/$1 [R=301,L]
# Skip the following rules if any of these filetypes are requested or if
# the requested URL resolve to a physically-existing file or directory
RewriteCond %{REQUEST_URI} \.(gif|jpe?g|png|ico|css|js|pdf|swf|flv|avi|wmv)$ [OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
#
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
First: Is the "?" in "jpe?g" a typo?
Second: What is RewriteRule ^ - [L] saying? Do nothing?
Third: The last 3 lines. I should replace these directories with whatever directories I have on my website?