Question

I am trying to redirect a link ONLY if it's www.domain to a subdomain admin.domain I have been looking around and I am thinking it's my syntax messing me up. I am not so great with .htaccess redirects and rewrites. Here is what I have used so far.

Example 1

RewriteCond %{HTTP_HOST} !^www.mydomain.com$
RedirectMatch 301 ^/wp-admin/?(.*)$ http://admin.mydomain.com/wp-admin/$1

Here is the second on I also have been trying.

RewriteCond %{HTTP_HOST} !^www.mydomain.com$
RewriteRule ^/wp-admin/(.*)$ http://admin.mydomain.com/wp-admin/$1 [QSA,L,R=301]

This is working off an amazon AWS cluster so the code needs to stop once it rewrites only with www. That is where the loop keeps happening.

Any help would be deeply appreciated!

Was it helpful?

Solution

I think you got it backwards, you want to redirect IF the host is www.mydomain.com, not when it ISN'T. So get rid of the !:

RewriteCond %{HTTP_HOST} ^www.mydomain.com$ [NC]
RewriteRule ^/?wp-admin/(.*)$ http://admin.mydomain.com/wp-admin/$1 [QSA,L,R=301]

Note that the first code block you have won't work at all. You're using a mod_rewrite condition with a mod_alias directive, they're completely independent of each other.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top