adasdasd adasdasd - 3 months ago 26
Apache Configuration Question

.htaccess folder/subdomain rewrite rule

I am going through a strange behaviour of .htaccess.

I am writing a rule of .htaccess to convert the below url :

I want to convert the following URL (where

site
is variable.)

www.xyz.com/domain/site


to

site.xyz.com/


Note that
/site
is generated at runtime. (Created by user)

But my rule is not working.

MY CODE

Options +FollowSymLinks
RewriteEngine On

RewriteBase /

RewriteCond %{HTTP_HOST} !www.xyz.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-]+).xyz.com [NC]
RewriteRule (.*) nono.html?sm=%2 [NC,QSA]

Answer

I got your issue.

your re-write rule is just opposite..

use this for your exact problem

and it will work

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST}%{REQUEST_URI}   ^(www\.)?xyz.com/domain/(.+)$(.*)
RewriteRule  (.*)  https://$1.xyz.com/  [L]
Comments