jimhermann

Well-Known Member
Jan 20, 2008
76
3
58
cPanel Community,

I want to have http://www.domain-name.tld/mailman/listinfo redirected to http://domain-name.tld/mailman/listinfo (without the www.)

I added some Rewrite Rules to the Post VirtualHost Include (/usr/local/apache/conf/includes/post_virtualhost_global.conf) using the cPanel Include Editor for all Apache version.

The Rewrite Rules did not work, so I tried a simple Rewrite Rule that works in /home/domain-username/public_html/.htaccess:

RewriteEngine On

RewriteLog "/var/log/rewrite.log"
RewriteLogLevel 2

RewriteCond %{HTTP_HOST} ^www\.domain-name\.tld$ [NC]
RewriteRule ^(.*)$ http://domain-name.tld/$1 [R,L]


The RewriteLog and RewriteLogLevel commands are effective, so I know that Apache is reading the file.

However, the RewriteRule is not effective.

What am I doing wrong? Is the HTTP_HOST not available at this point?

The Rewrite Logs do not show that Apache evaluated the Rewrite Rule for domain-name.tld

I tried putting the same commands in /usr/local/apache/conf/userdata/mailman.conf and got the same results.

# /scripts/verify_vhost_includes
Testing /usr/local/apache/conf/userdata/mailman.conf...ok

Jim
 

cPanelTristan

Quality Assurance Analyst
Staff member
Oct 2, 2010
7,607
43
348
somewhere over the rainbow
cPanel Access Level
Root Administrator

jimhermann

Well-Known Member
Jan 20, 2008
76
3
58
Mailman is handled at this location:

/usr/local/cpanel/3rdparty/mailman/cgi-bin/

You can create an .htaccess file there with rewrite rules. There are discussions about forcing https in this thread post that have similarities (rewriting the urls for all mailman list accounts) to your current rewrite request:

http://forums.cpanel.net/f145/case-...pci-compliance-feature-152153.html#post693186
Rewriting the domain name is harder than switching from HTTP to HTTPS. Here is what I had to add to httpd.conf or .htaccess:

RewriteEngine On

RewriteMap strip_www prg:/usr/local/cpanel/3rdparty/mailman/bin/strip_www.pl

RewriteCond %{REQUEST_URI} ^/mailman
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*)$ http://${strip_www:%{HTTP_HOST}}/$1 [R,L]

where /usr/local/cpanel/3rdparty/mailman/bin/strip_www.pl contains:

#!/usr/bin/perl
$| = 1;
while (<STDIN>) {
$_ =~ s/www\.//;
print $_;
}

It works, but loads 423 perl strip_www.pl processes when I start httpd. It's the nature of Apache beast.

I think that I would better off creating individual httpd.conf files for each domain name in:

/usr/local/apache/conf/userdata/std/2/$username/$domainname

RewriteEngine On

RewriteCond %{REQUEST_URI} ^/mailman
RewriteCond %{HTTP_HOST} ^www.$domainname$ [NC]
RewriteRule ^/(.*)$ http://$domainname/$1 [R,L]

where $username and $domainname have to be different for each site.

I haven't tried this yet.

Jim
 

cPanelTristan

Quality Assurance Analyst
Staff member
Oct 2, 2010
7,607
43
348
somewhere over the rainbow
cPanel Access Level
Root Administrator
I'm uncertain why an .htaccess at /usr/local/cpanel/3rdparty/mailman/cgi-bin wasn't used as my link suggested (of note, /usr/local/cpanel/3rdparty/mailman/bin is not the same as cgi-bin). Now, you cannot use httpd.conf files for each domain because, as I already indicated, the rewrite needs to be in mailman's cgi-bin. This is why it is recommended in all the posts where discussion of mailman rewrites are discussed to put the rewrites into the .htaccess file for mailman itself.

This would work for every domain if you put it in /usr/local/cpanel/3rdparty/mailman/cgi-bin location:

Code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/mailman/$1 [R=301,L]
I tested it, and it redirects mailman's list no matter what domain from www.domain.com/mailman/whatever to domain.com/mailman/whatever and it only does it for mailman b/c it's in mailman's cgi-bin

Thanks!
 

jimhermann

Well-Known Member
Jan 20, 2008
76
3
58
I'm uncertain why an .htaccess at /usr/local/cpanel/3rdparty/mailman/cgi-bin wasn't used as my link suggested (of note, /usr/local/cpanel/3rdparty/mailman/bin is not the same as cgi-bin). Now, you cannot use httpd.conf files for each domain because, as I already indicated, the rewrite needs to be in mailman's cgi-bin. This is why it is recommended in all the posts where discussion of mailman rewrites are discussed to put the rewrites into the .htaccess file for mailman itself.

This would work for every domain if you put it in /usr/local/cpanel/3rdparty/mailman/cgi-bin location:

Code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/mailman/$1 [R=301,L]
I tested it, and it redirects mailman's list no matter what domain from www.domain.com/mailman/whatever to domain.com/mailman/whatever and it only does it for mailman b/c it's in mailman's cgi-bin

Thanks!
Very nice. I liked it and replaced my RewriteMap with your code.

BTW, both codes work in /usr/local/apache/conf/userdata/mailman.conf also. You're right. They won't work in /home/username/public_html/.htaccess because it is never loaded for URI /mailman. However, /usr/local/apache/conf/userdata/*.conf is included in the httpd.conf, so it is always loaded with every virtual domain. I found this solution before you posted your message.

Thanks again.

Jim
 

jimhermann

Well-Known Member
Jan 20, 2008
76
3
58