Htaccess for Wordpess set on single subdomain

admin2025-06-06  1

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 and "B" to use subdomain.domain

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]

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 and "B" to use subdomain.domain

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]
Share Improve this question edited Feb 9, 2017 at 7:42 DDos Schwagins asked Feb 3, 2017 at 10:29 DDos SchwaginsDDos Schwagins 1911 gold badge1 silver badge8 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 6

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\$
RewriteRule ^(.*)$ "https://domain/$1" [R=301,L]

After that, your .htaccess for domain will be like:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} !^domain\$
RewriteRule ^(.*)$ "https://domain/$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, it'll be like:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} !^subdomain\.domain\$
RewriteRule ^(.*)$ "https://subdomain.domain/$1" [R=301,L]

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Reasons:

  1. Using standard CODE is recommended because it's easier to maintain & debug, as it's same everywhere.

  2. 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.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749151105a316801.html

最新回复(0)