문제

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!

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top