Situation
- I have standard hosting in OVH (not VPS) and I’m able to set many websites on it in a different subdirectories,
- I would like to install 2 instances of WordPress – first in directory
/A
and secend in directory/B
- I would like “A” to use
domain.com
and “B” to usesubdomain.domain.com
Question
- In that case need I use standard
.htaccess
configuration for WordPress on a single domain in each WordPress directory or have I to use special configuration for subdomain in each WordPress directory ?
Domain
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
SubDomain
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ $1 [L]
RewriteRule . index.php [L]
- or maybe should I use subdirectory version of
.httaccess
?
SubFolder
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
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]
1 Answer
My suggestion is: use the same standard .htaccess
configuration for WordPress on a single domain in each WordPress directory.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Along with it, add a small CODE to make sure users are redirected to the correct domain in case they reach to that subdirectory using another domain:
RewriteCond %{HTTP_HOST} !^domain\.com$
RewriteRule ^(.*)$ "https://domain.com/$1" [R=301,L]
After that, your .htaccess
for domain.com
will be like:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^domain\.com$
RewriteRule ^(.*)$ "https://domain.com/$1" [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
and for subdomain.domain.com
, it’ll be like:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^subdomain\.domain\.com$
RewriteRule ^(.*)$ "https://subdomain.domain.com/$1" [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Reasons:
-
Using standard CODE is recommended because it’s easier to maintain & debug, as it’s same everywhere.
-
The extra two line are recommended mainly for
SEO
. Without them, one of your domain may be accessible using another domain. That may raise some duplicate content question.