Htaccess subdomain with access to subfolders

I am trying to rewrite a subdomain request to a subfolder on my server using .htaccess

. I want to mail.domain.com

look into the folder mail

located at the root. I can achieve this with the code below.

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

      

It WORKS correctly. When I browse mail.domain.com

, I get the content domain.com/mail/index.php

.

However, this does not work with subfolders within a subdomain. those. when i browse mail.domain.com/installer

it does NOT give content from domain.com/mail/installer/index.php

. Instead, it shows a 404 error. I also tried the code from htaccess specifying a subdomain . For some reason I can't get the exit. This method also gives the same problem. What am I doing wrong?

Note:

  • I don't want to redirect conditions. Want to achieve rewrite rules.
  • I am using openshift server. created aliases domain.com

    and mail.domain.com

    .
  • 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 everything works well. So it throws 404 error on subdomains subdomains. Please help, what can I do for WordPress how pretty urls and subdomains subdomains work?

Note: I'm sorry. Wordpress added this via the web interface and I didn't notice it.

+3


source to share


1 answer


Save 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]

      

+1


source







All Articles