htaccess of virtual subdomain with subfolders
currently i have achieved
www.username.domain.com to redirect to domain.com/folder1/folder2/index.php?id=username
with my current .htacceess
RewriteCond %{HTTP_HOST} !开发者_运维百科^www\.domain\.com$
RewriteCond %{HTTP_HOST} ^www\.(.*)\.domain\.com$
RewriteRule ^$ http://domain.com/general/user/index.php?id=%1 [P,L]
i want to achieve this
www.username.domain.com/pagename/
to redirect to domain.com/folder1/folder2/next.php?id=username
www.username.domain.com/pagename/variable
to redirect to domain.com/folder1/folder2/next.php?id=username$val=variable
Please help
Use this rule (place after yours):
RewriteCond %{HTTP_HOST} !^www\.domain\.com$
RewriteCond %{HTTP_HOST} ^www\.(.*)\.domain\.com$
RewriteRule ^pagename/([^/]*)$ http://domain.com/folder1/folder2/next.php?id=%1&val=$1 [P,L]
This will work for both www.username.domain.com/pagename/
and www.username.domain.com/pagename/variable
(for 1st URL value of val=
will be empty string).
P.S.
I assume $
character is a typo in your 2nd destination URL (domain.com/folder1/folder2/next.php?id=username$val=variable
) and it should be &
instead.
精彩评论