user3131517
user3131517

Reputation: 23

.htaccess multiple rewrite conditions and rules

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

Answers (1)

anubhava
anubhava

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

Related Questions