Need to redirect folders like sub-domain within sa

2019-08-10 05:08发布

Currently my URL is like http://vidleap.com/nov5and151/index.html and now I want to redirect this URL like http://nov5and151.vidleap.com/index.html. So how to do it via htaccess?

I am using below code but it's not working.

    <IfModule mod_rewrite.c>
        <IfModule mod_negotiation.c>
            Options -MultiViews
        </IfModule>

        RewriteEngine On
        RewriteBase /

        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^ index.php [QSA,L]

        RewriteCond %{HTTP_HOST} ^(?:www\.)?vidleap\.com [NC]
        RewriteRule ^([^/]+)(/.*)?$ http://www.$1.vidleap.com$2 [R=301,L,NC]

        RewriteCond %{HTTP_HOST} ^www\.(.+)\.vidleap\.com [NC]
        RewriteRule ^(.*)$ /%1/$1 [L]
    </IfModule>

2条回答
你好瞎i
2楼-- · 2019-08-10 05:55

Try these rules in different order:

<IfModule mod_negotiation.c>
     Options -MultiViews
</IfModule>

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteCond %{HTTP_HOST} ^(?:www\.)?domain\.com [NC]
RewriteRule ^([^/]+)(/.*)?$ http://www.$1.domain.com$2 [R=301,L]

RewriteCond %{HTTP_HOST} ^www\.(.+)\.domain\.com [NC]
RewriteRule ^(.*)$ /%1/$1 [L]

RewriteRule ^ index.php [L]

Make sure to clear your browser cache.

查看更多
Summer. ? 凉城
3楼-- · 2019-08-10 05:57

You can try these :-

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com
RewriteRule ^(.*)$ http://domain.com/%1/$1 [L,NC,QSA]
查看更多
登录 后发表回答