apache rewrite

Chris Grau chris at chrisgrau.com
Fri May 20 16:42:00 UTC 2005


On Fri, May 20, 2005 at 05:13:14PM +0100, Shahzad Chohan wrote:
> Hi Guys,
> 
> Wonder if you can help me.
> 
> I have a url where I want to redirect everything and return a 301. But
> I want the base url and /index.html
> 
> to not redirect.
> 
> Can someone please explain how I can do this?

That should be pretty easy with mod_rewrite.  Just off the top of my
head:

  RewriteEngine On
  RewriteCond %{REQUEST_URI} !^/$
  RewriteCond %{REQUEST_URI} !^/index.html$
  RewriteRule ^/(.*) http://www.example.com/$1 [R=301,L]

The two RewriteCond directives tell mod_rewrite not to execute the rule
for those conditions (the matches are negated by the !).  Everything
else is redirected with status 301 by the RewriteRule.

For more info on how this works, the mod_rewrite document is pretty
informative:

  http://httpd.apache.org/docs/mod/mod_rewrite.html
  http://httpd.apache.org/docs-2.0/mod/mod_rewrite.html

> Thanks
> Shaz

-chris




More information about the fedora-list mailing list