Forum Moderators: phranque

Message Too Old, No Replies

Getting the last folder with mod rewrite.

is it possible?

         

ibiza

12:33 pm on Jan 30, 2005 (gmt 0)

10+ Year Member



I've searched everywhere, and I can't find the answer to this question.

Say I have a URL like this:
[example.com...]

or simply
[example.com...]

What is important here is the last folder. That is what I need to get. However, there could by any number of folders before LastFolder. Is there anyway to retrieve the name of the last folder?

Basically, I'm look for something like

RewriteRule ^directory/...any_number_of_folders_here.../(.*)/ index.php?dir=$1

Thanks for the help.

jdMorgan

4:50 pm on Jan 30, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



ibiza,

I assume you're asking about code for use in .htaccess as opposed to httpd.conf. If so, try this:


RewriteCond %{REQUEST_URI} !^/index\.php$
RewriteCond %{REQUEST_URI} /([^/]+)/?$
RewriteRule .+ /index.php?dir=%1 [L]

The code for use in httpd.conf is simpler, but won't work in .htaccess:

RewriteCond %{REQUEST_URI} !^/index\.php$
RewriteRule /([^/]+)/?$ /index.php?dir=$1 [L]

The difference is that the leading slash is stripped off the requested URL-path in .htaccess context.

Jim