0

From this answer on how to redirect a domain except for a subdirectory, and this answer on how to redirect a domain except for the homepage, I have ended up with the following in .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>

However, this.example.com/work is not redirecting to www.this2.com/work.

Help appreciated.

Update, from anubhava's answer, this is my new .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>

However, https://doig.website.technology/my-work/ is not redirecting.

Update 2: this is my full .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
Steve
  • 2,066
  • 13
  • 60
  • 115

1 Answers1

0

You may use this rule with corrected syntax of consitions:

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]
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • Thanks anubhava, I've tried that with no luck, see the edit to my question please. – Steve Jul 07 '19 at 11:50
  • Do you have other rules in your htacceas? – anubhava Jul 07 '19 at 13:05
  • `/my-work/` does not have a separate `.htaccess`. I've updated my question with the full `.htaccess`. Thanks. – Steve Jul 14 '19 at 09:03
  • I notice the solution works when I moved your rules to the top of `.htaccess`. However, `https://doig.website.technology/` is missing style sheets, even though I have excluded `/wp-content/` & `/wp-includes`/ from the redirect in `.htaccess`. – Steve Jul 14 '19 at 09:09
  • Problem is links like `https://doig.website.technology/min/932c2.css` that get redirected to `https://www.webby.net.au/min/932c2.css` and return 404 – anubhava Jul 14 '19 at 09:29