php - directing url through htaccess -
i know code below
rewriteengine on rewritecond %{http_host} !^www\. rewriterule ^(.*)$ http://www.%{http_host}/$1 [r=301,l]
is use add www http host every time url access without www.
similarly code
rewriteengine on rewritecond %{request_filename} !-d rewritecond %{request_filename} !-f rewritecond %{request_filename} !-l rewriterule ^(.+)$ index.php?url=$1 [qsa,l]
is use posting every thing in url index.php in value of url variable. without changing url in first example (which change url without www www).
what want little tricky.
i want if there no www first example steps should performed.
and if there www, or other text, e.g. forum.site.com or blog.site.com or www.site.com in second example, should silently direct folder of same name.
ee.g. if www, should rewrite folder www/
folowed variable.
like visitor type www.site.com should load files www/ folder , if visitor type www.site.com/index.php?pid=1 should rewritten www/ folder along index.php?pid=1
data
and same should go for thing other www. fourm.site.com/index.php?blah=blahblah etc.
hope m not confusing , not breaking rules.
rewriteengine on rewritecond %{http_host} !^.+{3,} rewriterule ^(.*)$ http://www.%{http_host}/$1 [r=301,l] rewritecond %{http_host} ^(.*)\.(.+\..+) rewriterule ^(.*)$ http://%2/%1/$1 [qsa,l]
the algorithm of 2-nd rule this:
- i check, host consists of @ least 3 parts, separated dots. it's not ideal solution, cause there domains, naturally having 3 parts .co.uk , .com.br. but, assume, using domain of 2 parts.
- so, if there 3 parts, like: www.site.com, put 1-st part %1 , 2-nd part %2. so, %1 = 'www', %2 = 'site.com'.
- redirect
http:://site.com/www/request
if have 3 parts domain, site.co.uk, can make more complicated rule:
rewritecond %{http_host} ^(.*)\.(.+\..+\..+) rewriterule ^(.*)$ http://%2/%1/$1 [qsa,l]
this rewrite: subdomain.site.co.uk
http://site.co.uk/subdomain/
Comments
Post a Comment