Page 1 of 1

.htaccess required

Posted: Fri Apr 20, 2007 10:27 pm
by alex.barylski
Would someone be able to provide me the following code for a .htaccess as follows:

I have a index.php which sits in a directory as follows.

Code: Select all

home/
  index.php
  dir1/
    dir2/
      step1/
      step2/
      step3/
      step4/
  resource/

I want to allow users the ability to access

Code: Select all

dir1/dir2/step1/
dir1/dir2/step2/
dir1/dir2/step3/
...
However I need each of those accesses to go through index.php - if that makes any sense :P (i'm tired - long day)

Here is the real kicker.

Ideally I would like each of those 'step' directories to be accessed with a cleaner URL so instead of

dir1/dir2/step1

I would prefer 'step1'

example:

http://www.domain.com/step1 maps to http://www.domain.com/dir1/dir2/step1/

I also need those rewrite rules to *ignore* accesses like:

http://www.domain.com/resource

But everything else is game and should redirect through index.php

I'm sure this is possible, but I have no idea how...

The last time I tried .htaccess I also observed that any GET parameters were not sent in, so I assumed I had to parse the REQUEST_URI manually...it would be nice if that wasn't the case and my GET parameters were just availble.

Can someone please show me how this is done as well as an explanation...I'd greatly appreciate it :)

Posted: Fri Apr 20, 2007 10:41 pm
by alex.barylski
Just to note:

This is what I have thus far, which seems to work, but I'm wonder if it's ideal???

It seems to preserve my other GET vars and redirects everything thgouh index.php but how do I keep resources "normally" accessible?

Thanks

Code: Select all

RewriteEngine on
RewriteRule ^(.+)$ index.php?page=$1 [QSA]

Posted: Fri Apr 20, 2007 10:43 pm
by John Cartwright

Code: Select all

RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^/step([0-9]+)$ index.php?p=$1/
Only got a minute, I'll follow up tommorow.

Hopefully this is what you are looking for

Posted: Fri Apr 20, 2007 10:54 pm
by alex.barylski
Hehe...

Looks good to me, but I have no idea what I'm looking at...I should really read up on mod_rewrite :P

Ok, new requirement...if you wouldn't mind :)

I want to map

http://www.domain.com/some/dir/here

to simple

http://www.domain.com/here

The code I provided does this and I imagine yours will too. However

I need some exceptions.

For one, 'resources' which is accessible

http://www.domain.com/resources

Must be accessible normally (no rewriting). Also a directory under each rewritten directory called 'images' must no be rewritten

So

http://www.domain.com/some/dir/here/images

Must remain normally accessible - obviously because they are images and need to be accessed as such. Make sense?

Is this still possible?

http://www.domain.com/some/dir/here => http://www.domain.com/here but everything under http://www.domain.com/some/dir/here/images stays put.

'Here' is a placeholder and can actually be any number of values.

EDIT Also, I need to be able to access 3 or 4 files which are sibliings to index.php (test1.php, trick.php, etc)

Cheers and thanks again :)