lolbas
lolbas

Reputation: 794

.htaccess process subdomain with domain

I have directory structure as follows:

/var/www/example/
├── example.com
│   └── index.php
└── sub.example.com
    └── .htaccess

.htaccess files content:

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(.*)\.example\.com$
RewriteRule ^/?$ /var/www/example/example.com/index.php

What I am trying to achieve is whenever user visits subdomain sub.example.com request will be processed by index.php of main domain without browser redirecting to example.com, but instead it says 404 Not Found.

I also tried using DocumentRoot /var/www/example/example.com but it lead to 500 Internal Server Error.

Upvotes: 0

Views: 53

Answers (1)

Cesur APAYDIN
Cesur APAYDIN

Reputation: 836

You can do it without htaccess using Symlink.

Using Server Console:

// All Files Symlink (Directory)
cd /var/www/example
ln -s example.com sub.example.com

// Custom Files Symlink (index.php)
cd /var/www/example/sub.example.com
ln -s "../example.com/index.php" "index.php"

Upvotes: 1

Related Questions