Karthik
Karthik

Reputation: 1751

htaccess subdomain with subfolders access

I am trying to rewrite the subdomain request to a subfolder in my server using .htaccess. I want mail.domain.com to look into mail folder located in the root. I am able to achieve this with the below code

RewriteEngine on
RewriteCond %{HTTP_HOST} mail.domain.com$
RewriteCond %{REQUEST_URI} !^/mail
RewriteRule ^(.*)$ /mail/$1 [L]

This WORKS correctly. When i browse to mail.domain.com i am getting the contents of domain.com/mail/index.php.

However this doesn't work with the subfolders inside the subdomain. ie when i browse to mail.domain.com/installer it DOESN'T give the contents from domain.com/mail/installer/index.php. Instead it shows 404 error. I also tried the code from htaccess subdomain pointing . Somehow I am unable to get the output. That method also gives the same problem. What am I doing wrong?

Note:

  1. I do not want redirect conditions. Want to achieve via rewrite rules.
  2. I am using openshift server. created domain.com & mail.domain.com aliases.
  3. Root folder contains wordpress with no below .htaccess rules.

Edit

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

When I remove the above wordpress htaccess all works well. So it is causing 404 error in subdomain subfolders. Please help what i can do for both wordpress pretty urls and subdomain subfolders to work?

Note: I am really sorry. Wordpress added this via web interface and i failed to notice that.

Upvotes: 3

Views: 2144

Answers (1)

anubhava
anubhava

Reputation: 785058

Keep your root .htaccess like this:

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} =mail.domain.com
RewriteRule ^((?!mail).*)$ mail/$1 [L,NC]

RewriteRule ^(index\.php$|mail) - [L,NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

Upvotes: 1

Related Questions