简体   繁体   中英

.htaccess wildcard subdomain redirect with wildcard path 404 not found

I'm trying to redirect wildcard subdomains with a wildcard path and it seems to be working, however when the url has any path a 404 error is returned.

For example https://test.mydomain.com/ will redirect with no issues to https://new.mydomain.com/ while https://test.mydomain.com/test will return a 404 error not found. I need https://test.mydomain.com/test to redirect to https://new.mydomain.com/test

My current .htaccess file is as follows

RewriteEngine on

RewriteCond %{HTTP_HOST} ^\*\.mydomain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.\*\.mydomain\.com$
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)$ "https\:\/\/new\.mydomain\.com\/$1" [R=301,L]

Any help would be appreciated. Thanks

The issue might be that the redirect is being redirected, ie when test is redirected to new , that is being redirected again to new because of the * in the condition. Try editing as follows to not apply it to new.

RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com$ [NC]
RewriteCond %1 !^new$

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM