Reputation: 23
I am trying to solve multiple rewrite rules and conditions within one .htaccess file.
the file looks as following:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(jira.)?mydomain.com$
RewriteRule (.*) http://jira.mydomain.com:8080/jira/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^(confluence.)?mydomain.com$
RewriteRule (.*) confluence.mydomain.com:8099$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^(stash.)?mydomain.com$
RewriteRule (.*) stash.mydomain.com:7990/stash$1 [R=301,L]
So entering the domain jira.mydomain.com forwards me to jira.mydomain.com:8080/jira/ The first rewrite works fine the other two not.
Thank you for your help
Upvotes: 2
Views: 323
Reputation: 785146
It is due to faulty regex i.e. (jira.)?
, (stash.)?
etc which is making jira.
optional hence you first rule is always matching.
Try this code:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^jira\.mydomain\.com$ [NC]
RewriteRule (.*) http://jira.mydomain.com:8080/jira/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^confluence\.mydomain\.com$ [NC]
RewriteRule (.*) http://confluence.mydomain.com:8099/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^stash\.mydomain\.com$ [NC]
RewriteRule (.*) http://stash.mydomain.com:7990/stash/$1 [R=301,L]
Upvotes: 3