apache - htaccess folder rewrite -


i've been reading multiple posts on here htaccess folder rewriting none seem fit question (properly).

my question is:

i have 2 sub folders on server, website1 , website2.

when user goes www.foo.com wish visual url remain same want server uri go /website1/ load index.php website1

i want same thing when user goes www.bar.com again url not change time links /website2/ load index.php 2nd website.

would appreciate i'm still learning rewrites. examples explanations highly appreciated. advice of best practice (if any) appreciated.

kingcrunch right -- proper way setup such environment use <vistualhost> directive in apache config file.

if, whatever reason needs dona via rewrite , .htaccess .. need mod_rewrite enabled , .htaccess files allowed contain rewrite rule (allowoverride directive).

here rules:

options +followsymlinks -multiviews rewriteengine on rewritebase /  # rule #1 rewritecond %{http_host} =www.foo.com rewritecond %{request_uri} !^/website1/ rewriterule (.*) /website1/$1 [l]  # rule #2 rewritecond %{http_host} =www.bar.com rewritecond %{request_uri} !^/website2/ rewriterule (.*) /website2/$1 [l] 

this code placed in .htaccess file in root folder. if placed elsewhere (e.g. configuration or virtual host context) tweaking may required.

fist rule www.foo.com , second domain name. these rules pretty same. tell apache check domain name (via {http_host} request variable), , if matches our domain rewrite (internal redirect) url 1 folder deeper. second condition prevent rewrite loop (to not rewrite rewritten url). necessary apache after executing rewrite goes next rewrite iteration (that how works) , condition required stop loop.

useful link: http://httpd.apache.org/docs/current/rewrite/


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -