• 0

[APACHE] .htaccess subdomain redirect not working


Question

Hello all!

 

After GoDaddy gave me the finger when my Wordpress site was hacked and a trojan was uploaded (apparently basic web hosting SLA doesn't include restoration to their previous backups without a nice fee), I decided to use my own VPS with AWS Lightsail (It's cheaper and easier to set up compared to AWS EC2).

 

Anyway, I am trying to redirect the subdomain mail.domain.com to domain.com/mail (with URL masking, showing only mail.domain.com/pages), but the configuration is not working.

Below is a copy of my .htaccess file:

# Enable .htaccess files
RewriteEngine on
RewriteBase /
# Redirect mail.domain.com to domain.com/mail/, as well as any subdomain.domain.com to domain.com/subdomain
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} ^([^\.]+)\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://domain\.com/%1 [L,R]

Also, I have set AllowAccess all in my httpd.conf file.

I am using Amazon's AMI, which apparently is based off CentOS.

 

Thanks for the help all, I have tried several different ways from different sites and nothing works. I still do not completely understand this as I never had a need to do this until now.

1 answer to this question

Recommended Posts

  • 0

Redirecting mail.domain.com to domain.com/mail/ is a very strange thing to do :s

 

Since in most cases mail.domain.com is actually a redirect to domain.com/mail/ which means the pages should already be accessible at domain.com/mail :/

This topic is now closed to further replies.