开发者

Simple mod_rewrite and website dir structure

I am making a site with photo albums for agents. Each agent has his开发者_开发知识库 folder with .css file. Each agent dir has album folders with index.php and .css

/example.com/
    /agent001/
    agent001.css
        /000005/
        index.php
        main.css
        /photos/
            aaa.jpg
            bbb.jpg
        /000006/
        index.php
        ...
    /agent002/
    agent002.css
        /000009/
        ...

So the path to agent's 000005 album would be: /agent001/000005/index.php

I want a shortcut like: /000005/ which forwards to /agent001/000005/some-title-here

Another thing I can't really get my head around is my dir structure. I really need the agent and album folders to organize my stuff. But index.php and main.css are all the same, should I move these files to the root?

Any help greatly appreciated!


That is not possible with mod_rewrite. You would need some program that walks through the agent directories an checks if there is a folder with that name.

But besides that your short URLs would not be distinct any more. Because like Max S. said in the comments, how should /000005/ be mapped if more than one agent has an album “000005”? Or is this value unique for all agents?

And using a central instance of index.php and main.css is the best choice to avoid redundancy and complexity. In that case you could use mod_rewrite to rewrite requests to your central files like:

RewriteRule ^[^/]+/[^/]+/index\.php$ /index.php
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜