0

I install WP in main domain example.com and there is the .htaccess file:

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

</IfModule>

# END WordPress

How I can redirect the user who requests {subdomain}.example.com to app.example.com/{subdomain} but if they just want example.com to give them index.php file like it is now?

Also how to keep {subdomain}.example.com in the browser instead of showing app.example.com/{subdomain} ?

UPDATE: my wildcard subdomains are already redirected to the main domain ...

Aleks Per
  • 1,549
  • 7
  • 33
  • 68

1 Answers1

0

Even you can do it with PHP or JS

Add this lines at the top of your public_html/subdomain/index.php

<?php
  if($_SERVER[HTTP_HOST] == "example.com"){
    header("location:http://sub.example.com");
    exit();
 }

Since you are using WordPress , it would be better to use this code snippet at the top of your wp-blog-header.php And now you are all set.

Hasibul Hasn
  • 318
  • 5
  • 16