samsonite1023
asked on
Using a directory name as a parameter
I'd like to use a directory name as a parameter only if the directory does not exist at root level.
For instance,
http://www.mydomain.com/foo/
Should execute http://www.mydomain.com/index.php?param=foo
However, http://www.mydomain.com/ExistingFolder/
Should execute http://www.mydomain.com/ExistingFolder/index.php
This only needs to be done at root level... eg:
http://www.mydomain.com/ExistingFolder/foo
should *not* execute http://www.mydomain.com/ExistingFolder/index.php?param=foo
but rather http://www.mydomain.com/ExistingFolder/foo/
Thanks,
-Sam
For instance,
http://www.mydomain.com/foo/
Should execute http://www.mydomain.com/index.php?param=foo
However, http://www.mydomain.com/ExistingFolder/
Should execute http://www.mydomain.com/ExistingFolder/index.php
This only needs to be done at root level... eg:
http://www.mydomain.com/ExistingFolder/foo
should *not* execute http://www.mydomain.com/ExistingFolder/index.php?param=foo
but rather http://www.mydomain.com/ExistingFolder/foo/
Thanks,
-Sam
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Please do not destroy this question.
ASKER
Ok, I changed the regex to just:
^/(.*)/$
Seems to be working the way I wanted it to.
-sam
^/(.*)/$
Seems to be working the way I wanted it to.
-sam
ASKER
DirectoryIndex index.html index.php index.html.var
RewriteEngine on
# check, if element is not a directory
RewriteCond c:/dev/htdocs/$1 !-d
RewriteRule ^([^/]+)/$ /index.php?param=$1 [L]
...and restarted the service. (I'm using apache2, but that shouldnt matter)
When I go to http://localhost/foo/ or http://localhost/foo/bar/ [foo doesnt exist]
I just get a 404.. no rewrite is attempted. http://localhost/index.php exists and echos $_GET['param']
Am I doing anything wrong?
Thanks,
-sam