Redirecting a home page using mod_rewrite
Archive - Originally posted on "The Horse's Mouth" - 2010-04-17 23:33:31 - Graham EllisRewriteEngine On
RewriteRule ^$ /community/index.php [R,L]
Subject line says it all, really ;-) ...
I've had some experimental stuff (with Joomla) on the "Transwilts Community Rail Partnership" site for a couple of weeks ... but at yesterdays very successful meeting of the working group, we decided to hide that and take over the URL as our own communications centre, with a small public facing element.
So - I have installed a "Simple Machines Forum" as a simple way of providing logins, and a posting capability under which any (registered) member of the group can put up material that can be either public or just "working discussion" within the group.
Without wishing to loose my original work, and yet not wanting a complex URL for the working group, I have used the mod_rewrite at the top. What does it mean?
"Any request for a completely empty URL on the server is to be redirected to /community/index.php; this is to be done by asking the browser to redirect (that's the "R" flag) and if this mod_rewrite directive is followed, it's the last rewrite (that's the "L" flag), so that the rewrite engine doesn't run on and attempt, additionally, to apply the Joomla rewrites.
So
- if you visit http://www.twcrp.org.uk/ you'll be redirected visibly to http://www.twcrp.org.uk/community/index.php
- if you visit http://www.twcrp.org.uk/index.php you'll have access to the Joomla experiments.
We cover the Apache web server (of which mod_rewrite is an element) on our Linux Web Server and Deploying LAMP courses. For programmers, we cover the uses of mod_rewrite on courses such as the PHP technology Workshop and Intermdiate PHP for leisure / hobby users