Forum Moderators: phranque
# Subdomain Redirect - Method 1
RewriteCond %{HTTP_HOST} ^example2.example1.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.example2.example1.com$
RewriteRule ^(.*)$ "http\:\/\/www\.example2\.com\/$1" [R=301,L]
# Subdomain Redirect - Method 2
rewritecond %{HTTP_HOST} !^www\.example2\.com$ [NC]
rewriterule ^(.*)$ http://www.example2.com/$1 [R=301,L]
we need one rather crucial bit of information that's missing from your post: what requests do you want to redirect?
RewriteCond %{HTTP_HOST} subdomain\.example\.com
RewriteRule (.*) http://www.subdomain.com/$1 [R=301,L]
Note that there are no anchors in the condition. That way, it covers with and without www, and also any appended port numbers (rare, but doesn't hurt to let the rule address those too). So anything for subdomain.example.com should go to subdomain.com ?
Does this happen in the same htaccess that's used by example.com (the real thing)? If so, the domain-name canonicalization redirect for the rest of example.com will have to go after this rule.
Options -Indexes
<files wp-config.php>
Order allow,deny
Deny from all
</files>
<files error_log>
Order allow,deny
Deny from all
</files>
RewriteEngine On
RewriteBase /
# Redirect index.html and index.php
RewriteCond %{THE_REQUEST} [A-Z]{3,9}\ /(([^/]+/)*)index\.(html|php)
RewriteRule index\.(html|php) http://www.subdomain.com/%1 [R=301,L]
# Force Trailing Slash
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.subdomain.com/$1/ [R=301,L]
# Redirect Subdomain
RewriteCond %{HTTP_HOST} subdomain\.example\.com
RewriteRule (.*) http://www.subdomain.com/$1 [R=301,L]
# Domain-name canonicalization redirect
RewriteCond %{HTTP_HOST} !^(www\.subdomain\.com)?$ [NC]
RewriteRule (.*) http://www.subdomain.com/$1 [R=301,L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Are you asking if this URL exists: example.subdomain.com?
is this the correct approach?
/example.com/
.htaccess
index.html (i.e. example.com/index.html)
/directory1 (files for example.com/directory1)
/directory2 (files for example.com/directory2)
/othersite (files for othersite.com, with further subdirectories, optionally including a further htaccess)
/thirdsite (files for thirdsite.com, ditto)
/yourname/
.htaccess (optional in this location)
/example.com (all files for example.com, optionally including its own htaccess)
/othersite (all files for othersite.com, ditto)
/thirdsite (all files for thirdsite.com, ditto)
# Domain-name canonicalization redirect
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$ [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress # Domain-name canonicalization redirect
RewriteCond %{HTTP_HOST} !^(www\.subdomain\.com)?$ [NC]
RewriteRule (.*) http://www.subdomain.com/$1 [R=301,L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
both htaccess files has the Wordpress htaccess code - is this correct?If each place has its own separate WP installations, then that's how it has to be.
subdomain redirect code BEFORE the # Domain-name canonicalization redirectYup, because there are two steps: FIRST redirect requests for "subdomain.example.com". THEN redirect the leftovers within "example.com". These two lines only appear in the htaccess for example.com.