问题
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