: Rewrite rule not working for redirect in subdomain hosted in a subdirectory of the main site I am running a WordPress network. This means there are multiple websites produced by one installation
I am running a WordPress network. This means there are multiple websites produced by one installation of WordPress. Each website is a subdomain of the parent website. WordPress handles the creation of subdomain websites through a wildcard subdomain entered into cPanel, which points /public_html, which is where WordPress lives.
This means there is one .htaccess file serving all subdomain sites.
My parent website is doig.com.au. My problem website is tech.doig.com.au.
I need to 301 redirect tech.doig.com.au/venom-media.html to tech.doig.com.au/portfolio/venom-media/.
Previously, I had the following in my .htaccess file:
RewriteCond %{HTTP_HOST} ^tech.doig.com.au$ [NC]
RewriteRule . - [S=120]
|
RewriteRule ^venom-media.html tech.doig.com.au/venom-media/ [R=301]
|
RewriteRule ^services.html/feed tech.doig.com.au/services/feed [L,R=301]
However, this no longer works.
This is my .htaccess file.
Why is the RewriteRule not working?
More posts by @Phylliss660
1 Comments
Sorted by latest first Latest Oldest Best
RewriteCond %{HTTP_HOST} ^tech.doig.com.au$ [NC]
RewriteRule . - [S=120]
You appear to be Skipping all of the relevant redirects when the HOST matches tech.doig.com.au, which would seem to be the opposite of what you are trying to achieve. As it stands, your redirect would only occur when the domain is not tech.doig.com.au.
It looks like your RewriteCond directive should be negated:
RewriteCond %{HTTP_HOST} !^tech.doig.com.au$ [NC]
The same is also true for another domain block in your .htaccess file, however, several rules in that section redirect to the other domain so I'm not sure what the intention is with that one.
For example:
## SUB DOMAIN: sub1
# If the HOST is NOT sub1 (note the negated (!) condition)
# then SKIP the next 120 rules that apply only to sub1
RewriteCond %{HTTP_HOST} !^sub1.example.com$ [NC]
RewriteRule . - [S=120]
# These rules will only apply when we are at sub1,
# since they would have been skipped otherwise
RewriteRule ^page1.html sub1.example.com/path/page1.html [R=301,L]
RewriteRule ^page2.html sub1.example.com/path/page2.html [R=301,L]
:
RewriteRule ^page120.html sub1.example.com/path/page120.html [R=301,L]
## SUB DOMAIN: sub2
# If the HOST is NOT sub2 then skip the next 40 rules
RewriteCond %{HTTP_HOST} !^sub2.example.com$ [NC]
RewriteRule . - [S=40]
# These rules will only apply when we are at sub2,
RewriteRule ^page1.html sub2.example.com/path/page1.html [R=301,L]
RewriteRule ^page2.html sub2.example.com/path/page2.html [R=301,L]
:
RewriteRule ^page40.html sub2.example.com/path/page40.html [R=301,L]
EDIT: The above still applies, however, you also have this block near the start of your .htaccess file which is possibly preventing all of your redirects from being actioned.
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule . index.php [L]
That 2nd RewriteRule appears to unconditionally rewrite all requests (other than the root) to index.php.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.