.htaccess如何重定向除主页和子目录以外的域

时间:2019-07-07 10:30:06

标签: .htaccess

this answer到如何重定向除子目录之外的域,以及从this answer到如何重定向除主页之外的域,我在.htaccess中得到了以下内容:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?this\.example.com$ [NC]
RewriteRule !^support !^directory-1 !^directory-2 (.+) https://www.this2.com%{REQUEST_URI} [NE,NC,R=301,L]
</IfModule>

但是,this.example.com/work没有重定向到www.this2.com/work

帮助表示赞赏。

更新,来自 anubhava ,这是我的新.htaccess

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^doig\.website\.technology$ [NC]
RewriteRule !^($|support|dynamic-keyword-module-drupal8|dynamic-keyword-plugin-joomla) https://www.webby.net.au%{REQUEST_URI} [NE,NC,R=301,L]
</IfModule>

但是,https://doig.website.technology/my-work/没有重定向。

更新2 :这是我完整的.htaccess文件:

# Redirects
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^doig\.website\.technology$ [NC]
RewriteRule !^($|support|dynamic-keyword-module-drupal8|dynamic-keyword-plugin-joomla|wp-content|wp-includes|wp-admin) https://www.webby.net.au%{REQUEST_URI} [NE,NC,R=301,L]
</IfModule>

# BEGIN LSCACHE
## LITESPEED WP CACHE PLUGIN - Do not edit the contents of this block! ##
<IfModule LiteSpeed>
RewriteEngine on
CacheLookup on
RewriteRule .* - [E=Cache-Control:no-autoflush]
RewriteRule min/\w+\.(css|js) - [E=cache-control:no-vary]
</IfModule>
## LITESPEED WP CACHE PLUGIN - Do not edit the contents of this block! ##
# END LSCACHE
# BEGIN litespeed noabort
<IfModule rewrite_module>
        RewriteEngine On
        RewriteRule .* - [E=noabort:1]
</IfModule>
# END litespeed noabort

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#RewriteRule ^support\/?(.*)$ "https\:\/\/doig\.website\.technology\/support\/$1" [R=301,L]
</IfModule>

<IfModule mod_rewrite.c>
        RewriteEngine On
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
        RewriteCond %{REQUEST_URI} ^/?wp\-content/+debug\.log$
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
        RewriteRule .* - [F,L,NC]
</IfModule>

<IfModule !mod_rewrite.c>
    <Files "debug.log">
    <IfModule mod_authz_core.c>
        Require all denied
    </IfModule>
    <IfModule !mod_authz_core.c>
        Order deny,allow
        Deny from all
    </IfModule>
    </Files>
</IfModule>

# BEGIN Wordpress (new)
<IfModule mod_rewrite.c>
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]
</IfModule>
# END Wordpress

# BEGIN MainWP

# END MainWP

# Wordfence WAF
<IfModule LiteSpeed>
php_value auto_prepend_file '/home3/user/public_html/wordfence-waf.php'
</IfModule>
<IfModule lsapi_module>
php_value auto_prepend_file '/home3/user/public_html/wordfence-waf.php'
</IfModule>
<Files ".user.ini">
<IfModule mod_authz_core.c>
    Require all denied
</IfModule>
<IfModule !mod_authz_core.c>
    Order deny,allow
    Deny from all
</IfModule>
</Files>
# END Wordfence WAF

1 个答案:

答案 0 :(得分:0)

您可以将此规则与正确的条件语法一起使用:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^doig\.website\.technology$ [NC]
RewriteCond %{THE_REQUEST} !/(min|support|dynamic-keyword-module-drupal8|dynamic-keyword-plugin-joomla|wp-content|wp-includes|wp-admin)/ [NC]
RewriteRule . https://www.webby.net.au%{REQUEST_URI} [NE,R=301,L]