PDA

View Full Version : redirect from folder only to index in parent folder



weegillis
10-03-2009, 05:46 PM
I'm trying to remove all the index pages from a set of image folders and use an index.php page in the parent folder to retrieve contents using a query string. It's not friendly, but I don't really care.

What I want is to take this,

/pictures/cars/

and make it into

/pictures/index.php?fd=cars

Everything is working for me, but I need to create the redirect before I remove the index pages that are in each sub-folder. It will also be necessary, one supposes, to redirect from the actual url, as well:

/pictures/cars/index.php

also redirected to

/pictures/index.php?fd=cars

I'm working toward using a single include to drive several dozen picture folders, themselves contained in section folders, using a discovery script to retrieve otherwise unknown contents. Right now I have it down to a single index in each pictures folder.

There is an index.php and an index1.php, the former acting as a slideshow, and the latter a still image viewer (clicking the picture in the slide show opens the still). Also, from the main section page there are links out to individual photos using their ID in the query string.

wige
10-03-2009, 11:40 PM
The following two rules should work:

RedirectMatch 301 ^/pictures/(.*)/$ /pictures/index.php?fd=$1
RedirectMatch 301 ^/pictures/(.*)/index.php$ /pictures/index.php?fd=$1

weegillis
10-05-2009, 01:29 AM
Thanks, wige. Just one problem:

How does one prevent Apache from rewriting '?' to '%3f' ? This is throwing an error that reports a url missing when in fact if you paste the url reported, the page opens.

wige
10-05-2009, 10:36 AM
Oh, Apache and it's query strings... you would probably need to use mod_rewrite then

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/pictures/.*/$ [OR]
RewriteCond %{REQUEST_URI} ^/pictures/.*/index.php$
RewriteRule ^/pictures/([a-z]*)/ /pictures/index.php?fd=$1