Need to redirect folders like sub-domain within same domain using htaccess

旧街凉风 提交于 2019-12-11 10:09:40

问题


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>

回答1:


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.




回答2:


You can try these :-

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com
RewriteRule ^(.*)$ http://domain.com/%1/$1 [L,NC,QSA]


来源:https://stackoverflow.com/questions/33579980/need-to-redirect-folders-like-sub-domain-within-same-domain-using-htaccess

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!