# Htaccess and file/directory redirection

**URL:** <https://www.ruby-forum.com/t/htaccess-and-file-directory-redirection/68770>\
**Category:** Radiant CMS\
**Created:** [September 15, 2006, 9:15am UTC](https://www.ruby-forum.com/t/htaccess-and-file-directory-redirection/68770 "2006-09-15T09:15:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pezdude](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a87d85/32.png) [@pezdude](https://www.ruby-forum.com/u/pezdude)\
**Post date:** [September 15, 2006, 9:15am UTC](https://www.ruby-forum.com/t/htaccess-and-file-directory-redirection/68770/1 "2006-09-15T09:15:21Z")

</div>

Hi,

I have a site, [http://uk.tug.org/](http://uk.tug.org/) , that has some ‘file’ URIs such as

[http://uk.tug.org/activities](http://uk.tug.org/activities)

> **[Baskerville](http://uk-tug-archive.tug.org/baskerville/)**
>
> Baskerville is the magazine of UK-TUG (though it is currently dormant). The archive of past issues from Volume 3 Number 1 to Volume 10 Number 3 is available below. CTAN hold most of these PDFs and …

and some ‘directory’ URIs such as

[http://uk.tug.org/Activities/](http://uk.tug.org/Activities/)  
[http://uk.tug.org/Baskerville/](http://uk.tug.org/Baskerville/)

Since Radiant is case sensitive, I would expect visiting

[http://uk.tug.org/Activities](http://uk.tug.org/Activities)

to 301 redirect to

[http://uk.tug.org/Activities/](http://uk.tug.org/Activities/)

as normally happens with Apache.

However, this is not working with the default Radiant .htaccess in  
place.

I have asked my host’s support team if there was something in their  
server level apache configuration that would alter things, but there  
isn’t - if I move the .htaccess to .htaccess.old then the directory  
behavior works as normal.

I am totally stumped 🙂

–  
Regards,  
Dave

---

<div class="post-metadata">

**Author:** ![pezdude](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a87d85/32.png) [@pezdude](https://www.ruby-forum.com/u/pezdude)\
**Post date:** [September 15, 2006, 2:36pm UTC](https://www.ruby-forum.com/t/htaccess-and-file-directory-redirection/68770/2 "2006-09-15T14:36:09Z")

</div>

You shouldn’t have a problem if the URL points directly to a file; the  
built-in rewrite rules take care of that. If it points to a directory,  
you  
may need something else, perhaps individual rewrite rules for those  
directories. Are you expecting directory listings or opening an index  
page  
(index.php or index.html or something) in those?

> From the Apache 2.0 docs:

Solution:

The solution to this subtle problem is to let the server add the  
trailing  
slash automatically. To do this correctly we have to use an external  
redirect, so the browser correctly requests subsequent images etc. If we  
only did a internal rewrite, this would only work for the directory  
page,  
but would go wrong when any images are included into this page with  
relative  
URLs, because the browser would request an in-lined object. For  
instance, a  
request for image.gif in /~quux/foo/index.html would become  
/~quux/image.gifwithout the external redirect!

So, to do this trick we write:

RewriteEngine on  
RewriteBase /~quux/  
RewriteRule ^foo\*$\* foo\*/\* [_R_]

The crazy and lazy can even do the following in the top-level .htaccess  
file  
of their homedir. But notice that this creates some processing overhead.

RewriteEngine on  
RewriteBase /~quux/  
RewriteCond %{REQUEST\_FILENAME} _-d_  
RewriteRule ^(.+_[^/]_)$ $1\*/\* [R]

Sean C.  
[seancribbs.com](http://seancribbs.com)
