Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic Apache Alias and Redirect

Status
Not open for further replies.

sera

Technical User
Jun 29, 2000
360
US
Problem:

My boss wants his website to have logical tree like directories (URL) that match the menu tree for their site.
ex. in the menu there is:

Parentmenu Item
Childmenu Item
Grandchildmenu Item

They dont want anything in the get header. They want links to be logical looking and easy to remember.


Solutions (semi successful):

My first solution was to make the directories and copy the index.php into the dir. The index.php only includes the main index.inc file from the document root. The index.inc file parses out where in the directory structure we are, and determines the category of articles to display. This actually works well if you dont want to change the menu often. It requires manual install and changes to menus and creating directories and copying the index.php into the new directory. So we decided to try to make this more dynamic. I could write a script that makes the dir and copies the index.php into the dir and updates the category db. But I would rather eliminate these stub directories altogether. So...

There are a couple things I tried. First Ryan Proctor suggested that I use the 404 redirect to point back to the document root index.php. Then parse out the $_SERVER['REQUEST_URI'] and see what directory was requested. This actually worked BUT you can't pass anything inthe POST or GET because 404 drops all that and redirects. So I would have to build my own POST. I'm not excited about that. So I pretty much scraped that idea.

The latest idea is to use the Apache Alias module. I can specify a fake directory to use the document root as its home. This will be transparent to the user. I will have to still parse out the REQUEST_URI but should be able to pass values through the POST or GET. The problem with this is it requires a new line in httpd.conf and a restart of Apache in order for a new alias to take effect. This last step is not very smart to do with a script. We can write a script that only a locally logged in admin can run that will update the httpd.conf and restart Apache. That way at least an admin is sitting there while the restart takes place, incase something bad happens...


Future Ideas:

The last solution is my best try so far. If anyone can think of a better way, please chime in... I'm sure there is a more elegant way of achieving this solution. I think this is going to be an Apache configuration problem. I'm not familiar enough with mod_rewrite but think it might be of help. I'm looking for a way to dynamically redirect different URLs to document root. If i could use wildcards in mod_alias this would work, but that is a no go. Pointers and suggestions welcome.

Sera
 
I am extremely new to Apache - but i have been doing some reading lately - and i think you may well be right about the rewrite rule

I'll come back after some thought...

(I might not be of any help though!)


Kind Regards
Duncan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top