URL development and mod_rewrite

Posted by iRector on Stack Overflow See other posts from Stack Overflow or by iRector
Published on 2012-11-20T04:46:52Z Indexed on 2012/11/20 4:59 UTC
Read the original article Hit count: 243

Filed under:
|
|

My site is made-up of the main page, and multiple sub-directories, all under the same domain.

My URLS are currently like .................| Ideal clean version:


  • mysite.com
    • mysite.com/?content=content1 ......................| mysite.com/content1/
    • mysite.com/?content=content2&page=4 ........| mysite.com/content2/4/
    • mysite.com/?content=content3 ......................| mysite.com/content3/
    • mysite.com/?content=content4 ......................| mysite.com/content4/
    • mysite.com/?content=article&id=34 ............| mysite.com/article/34/

Then the sub-directories are essentially the same:

  • mysite.com/subdir, mysite.com/subdir2, mysite.com/subdir3, etc
    • mysite.com/subdir/?content=content1 ...................| mysite.com/subdir/content1/
    • mysite.com/subdir/?content=content2&page=4 .....| mysite.com/subdir/content2/4/
    • mysite.com/subdir/?content=content3 ...................| mysite.com/subdir/content3/
    • mysite.com/subdir/?content=content4 ...................| mysite.com/subdir/content4/
    • mysite.com/subdir/?content=article&id=34 .........| mysite.com/subdir/article/34/

I've used mod_rewrite briefly, but I'm not sure how to approach these multiple variables. Also, how would I differentiate between the actually subfolders, and the content variable. As so to prevent 'subdir' or 'subdir2' from being plugged in as the content variable for the root site.

I've played around with plenty of code snippets, but I've wiped my .htaccess slate clean, and approach you all in an attempt to help me repopulate it. Your input would thoroughly be appreciated.


Note: The only time the page query string will be needed is when 'content' == 'content2'

?content=content2&page=4

**Same rule is shared by the article/id relationship, all other 'content' values are expected to be dynamic.

© Stack Overflow or respective owner

Related posts about php

Related posts about url