Textpattern CMS support forum
- Registered: 2006-08-06
- Posts: 12
[howto] Textpattern page with same name as directory
I’m working on a site, and there’s a directory called /photos/ that has image files in it. The site owner also wanted a page at that address, but still wanted to be able to link to the files within it. Here’s how I did it.
First, create a section called photos in the txp control panel. Next, write an article with what you want to go on the page and put it in the photos section. Then create an .htaccess file in the /photos/ directory, with this as the contents:
<IfModule mod_rewrite.c> RewriteEngine On RewriteRule !^. ../index.php </IfModule>
That’s it. Basically, it says if there’s nothing after the trailing slash of /photos/ in the url, use Textpattern to process the request. If there’s something after the trailing slash (/photos/myphoto.jpg for example) just serve the file as normal.
There’s a big limitation with this technique. You won’t be able to link directly to individual articles within that section, and if you try, you will get errors. You probably won’t even be able to have multiple pages or comments in this section. You could write a more complicated rewrite rule to remove these limitations, but if you just need a simple page like I did, this should work well as is.
PS I wanted to post this in the How-to section of the forum, but it looks like I don’t have privileges.
- From: Cyprus
- Registered: 2004-11-20
- Posts: 5,969