Forum Moderators: phranque

Message Too Old, No Replies

Total Site Rewrite EVERYTHING to root ( -images -stylesheet)

Is it posible without 100+ rules?

         

xeoncross

3:47 pm on Oct 13, 2006 (gmt 0)

10+ Year Member



I am a just learning .htaccess but I am having some trouble. I want to have "index.php" process EVERYTHING but I don't know how to get all of the dirs to always go back to the root dir ("/"). (All while still letting any images or stylesheets in the "/images/" dir get through!)

For instance, I would like to make:

somesite.com/dir1/dir2/dir3/dir4/
go to
index.php?dir1=$1&dir2=$2&dir3=$3&dir4=$4

and something like:

somesite.com/dir1/dir2
go to
index.php?dir1=$1&dir2=$2

All with the same rule. Is it possible to make a rewrite that can take any number of directories and add them to a query string? I know I could manual make 100 different rules for each dir combo, but there has to be a better way.

If not, maybe someone can just tell me how I can get:

somesite.com/dir1
and/or:
somesite.com/dir1/

to turn into

index.php?dir1=$1

And the second rule would be:

somesite.com/dir1/dir2
and/or:
somesite.com/dir1/dir2/

to

index.php?dir1=$1&dir2=$2

All while still letting any images or stylesheets in the "/images/" dir get through!

Here are some of the rule I have been trying:

Code:

Options +FollowSymlinks 
RewriteEngine on
RewriteBase /
RewriteRule ^/(.*)/(.*)$ index.php?dir1=$1&dir2=$2

RewriteRule ^([A-Za-z0-9-]+)/images/([A-Za-z0-9-]+)$ /images/$2 [L] RewriteRule ^([A-Za-z0-9-]+)/default.css$ default.css [L]
RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?dir=$1 [L]
RewriteRule ^([A-Za-z0-9-]+)?$ index.php?dir=$1 [L]

RewriteRule ^/(.+) drains.php?drains=$1 [L]
RewriteRule ^dir/(.+)/(.+) index.php?dir1=$1&dir2=$2 [nc]

RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule ^(.*)$ index.php?dir=$1 [L,QSA]

Any help would be appreciated! :D

jdMorgan

4:10 pm on Oct 13, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



To get started, see this thread [webmasterworld.com] in our forum library for an explanation of the process.

Jim