?
Solved

Using a directory name as a parameter

Posted on 2006-05-08
5
Medium Priority
?
202 Views
Last Modified: 2010-03-04
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
0
Comment
Question by:samsonite1023
  • 3
4 Comments
 
LVL 27

Accepted Solution

by:
caterham_www earned 400 total points
ID: 16635396
So only one folder is present?

So you don't have
/foo/bar/ --> /index.php?param=foo/bar?

DirectoryIndex index.php index.html index.htm
RewriteEngine on
# check, if element is not a directory
RewriteCond /full/physical/path/to/htdocs/$1 !-d
RewriteRule ^([^/]+)/$ /index.php?param=$1 [L]
0
 
LVL 1

Author Comment

by:samsonite1023
ID: 16792256
I modified http.conf to have the following:

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

0
 
LVL 1

Author Comment

by:samsonite1023
ID: 16792271
Please do not destroy this question.
0
 
LVL 1

Author Comment

by:samsonite1023
ID: 16793072
Ok, I changed the regex to just:

^/(.*)/$

Seems to be working the way I wanted it to.

-sam
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As Wikipedia explains 'robots.txt' as -- the robot exclusion standard, also known as the Robots Exclusion Protocol or robots.txt protocol, is a convention to prevent cooperating web spiders and other web robots from accessing all or part of a websit…
If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
Integration Management Part 2
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month16 days, 19 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question