I had mantis setup as www.example.com/mantis and now I've setup my httpd.conf to have it accessible at: mantis.example.com . Since I have many links referencing the earlier links, I need to redirect them to the new location.
This is what I have as my httpd.conf now:
<VirtualHost MYSERVERIP:80>
ServerAlias EXAMPLE.com
DocumentRoot /var/www/html/beta
ServerName EXAMPLE.com
UseCanonicalName On
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteLogLevel 5
RewriteLog "/var/www/html/htaccess.log"
RewriteRule ^/mantis/(.*) http://mantis.EXAMPLE.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
...
</IfModule>
</VirtualHost>
...
<VirtualHost MYSERVERIP:80>
ServerAlias mantis.EXAMPLE.com
DocumentRoot /var/www/html/mantis
ServerName mantis.EXAMPLE.com
UseCanonicalName On
</VirtualHost>
However, accessing http://www.EXAMPLE.com/mantis/view.php?id=17575 leads to:
http://guide.opendns.com/main?url=www.mantis.EXAMPLE.com%2Fview.php%3Fid%3D17575
which shows:
You tried to visit www.mantis.EXAMPLE.com, which is not loading.
Note the www. part. I dont understand where its coming from!!
The htaccess logs are as follows:
MYCLIENTIP - - [27/May/2011:09:40:57 +0000] [EXAMPLE.com/sid#2b4fab862578][rid#2b4fabeec150/initial] (2) init rewrite engine with requested uri /mantis/view.php
MYCLIENTIP - - [27/May/2011:09:40:57 +0000] [EXAMPLE.com/sid#2b4fab862578][rid#2b4fabeec150/initial] (3) applying pattern '^/mantis/(.*)' to uri '/mantis/view.php'
MYCLIENTIP - - [27/May/2011:09:40:57 +0000] [EXAMPLE.com/sid#2b4fab862578][rid#2b4fabeec150/initial] (2) rewrite '/mantis/view.php' -> 'http://mantis.EXAMPLE.com/view.php'
MYCLIENTIP - - [27/May/2011:09:40:57 +0000] [EXAMPLE.com/sid#2b4fab862578][rid#2b4fabeec150/initial] (2) explicitly forcing redirect with http://mantis.EXAMPLE.com/view.php
MYCLIENTIP - - [27/May/2011:09:40:57 +0000] [EXAMPLE.com/sid#2b4fab862578][rid#2b4fabeec150/initial] (1) escaping http://mantis.EXAMPLE.com/view.php for redirect
MYCLIENTIP - - [27/May/2011:09:40:57 +0000] [EXAMPLE.com/sid#2b4fab862578][rid#2b4fabeec150/initial] (1) redirect to http://mantis.EXAMPLE.com/view.php?id=17575 [REDIRECT/301]
Related: httpd.conf changes to allow www.mysite.com and www.mysite.com/mantis and phpmyadmin?
Edit 1
After changing httpd.conf to:
RewriteLogLevel 5
RewriteLog "/var/www/html/htaccess.log"
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteRule ^/mantis/(.*) http://mantis.EXAMPLE.com/$1 [L,R=301]
No luck still.
The log file is as:
MYCLIENTIP - - [27/May/2011:10:41:12 +0000] [EXAMPLE.com/sid#2b4fab856518][rid#2b4fabf06640/initial] (2) init rewrite engine with requested uri /mantis/view.php
MYCLIENTIP - - [27/May/2011:10:41:12 +0000] [EXAMPLE.com/sid#2b4fab856518][rid#2b4fabf06640/initial] (3) applying pattern '^' to uri '/mantis/view.php'
MYCLIENTIP - - [27/May/2011:10:41:12 +0000] [EXAMPLE.com/sid#2b4fab856518][rid#2b4fabf06640/initial] (4) RewriteCond: input='www.EXAMPLE.com' pattern='!^www\.' => not-matched
MYCLIENTIP - - [27/May/2011:10:41:12 +0000] [EXAMPLE.com/sid#2b4fab856518][rid#2b4fabf06640/initial] (3) applying pattern '^/mantis/(.*)' to uri '/mantis/view.php'
MYCLIENTIP - - [27/May/2011:10:41:12 +0000] [EXAMPLE.com/sid#2b4fab856518][rid#2b4fabf06640/initial] (2) rewrite '/mantis/view.php' -> 'http://mantis.EXAMPLE.com/view.php'
MYCLIENTIP - - [27/May/2011:10:41:12 +0000] [EXAMPLE.com/sid#2b4fab856518][rid#2b4fabf06640/initial] (2) explicitly forcing redirect with http://mantis.EXAMPLE.com/view.php
MYCLIENTIP - - [27/May/2011:10:41:12 +0000] [EXAMPLE.com/sid#2b4fab856518][rid#2b4fabf06640/initial] (1) escaping http://mantis.EXAMPLE.com/view.php for redirect
MYCLIENTIP - - [27/May/2011:10:41:12 +0000] [EXAMPLE.com/sid#2b4fab856518][rid#2b4fabf06640/initial] (1) redirect to http://mantis.EXAMPLE.com/view.php?id=17575 [REDIRECT/301]
Sigh... figured out the culprit...
There was an .htaccess in /mantis/ that was messing things up... :(
Just removed it and all working fine now!
Do you have
NameVirtualHost MYSERVERIP
directive in there? If not, I'm pretty sure adding that line to the top will fix your problem. Without it apache just ignores the host header and uses the first matching virtual host it finds based on IP, which is why its re-adding the www from the first vhost rewriterule.Well, examine this block here:
First line is correct.
Second gets the HTTP_HOST, which is now mantis.EXAMPLE.com.
Then the fourth line rewrites it to www.mantis.EXAMPLE.com
Easiest way to fix is to move the first line to underneath the fourth. Simple as that.
Try something like this, more simple.