.htaccess重写conditition忽略子域

Jac*_*aug 2 wordpress .htaccess

我的主要域名是Wordpress博客,其中.htaccess重写如下......

 <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
  </IfModule>
Run Code Online (Sandbox Code Playgroud)

这很好用,但我在同一个目录中有一个子域名,并且正在使用这个重写...

    RewriteCond %{SERVER_PORT} ^443$
    RewriteCond %{HTTP_HOST} ^my\.domain\.com$ [NC]
    RewriteCond %{REQUEST_URI} !^/my/
    RewriteRule ^(.*) /my/$1
Run Code Online (Sandbox Code Playgroud)

这是我的通配符SSL证书.这很好用,但如果子域中不存在该位置,我会得到wordpress的错误页面.我需要wordpress重写来忽略"我的"子域.我怎样才能做到这一点?

我在想......

  <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !^my\.domain\.com$ 
    RewriteRule . /index.php [L]
  </IfModule>
Run Code Online (Sandbox Code Playgroud)

但这不起作用,也试过这个....

  <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^my\.domain\.com - [L,NC]
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
  </IfModule>
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

小智 5

您可能应该通过在服务器名称上添加条件来忽略该域.

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{SERVER_NAME} !^my\.domain\.com
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)

另外,我前段时间遇到过一些困难,尝试将子域的htaccess更改为

RewriteBase /my 
Run Code Online (Sandbox Code Playgroud)

如果"我的"将是它所在的目录.