Grow your CSS skills. Land your dream job.

Need Help with .htaccess and PHP

  • # July 22, 2009 at 4:26 am

    Hi,

    Necessary Knowledge

    My .htaccess file redirects like this:
    domain.com/about to domain.com/index.php?page=about

    Code:
    RewriteRule ^([^/.]+)/?$ index.php?page=$1 [L]

    The "page" variable is used in a php include:

    Code:
    < ?php include_once($_SERVER['DOCUMENT_ROOT']."/contents/".$page.".html"); ?>

    The "contents" folder simply contains .html files that are included as the content

    Okay here’s the problem:

    I have a "subfolder" in the "contents" folder with additional .html files that I need to access
    Now I’m trying to redirect like this:
    domain.com/subfolder/about to domain.com/index.php?page=subfolder/about

    This works:

    Code:
    RewriteRule ^([^/.]+/[^/.]+)/?$ index.php?page=$1

    But now I can’t access the subfolder from: domain.com/subfolder/ because there is a ‘page’ variable

    Code:
    < ?php $page = $_GET['page']; if(!$page) { $page = 'index'; } ?>

    Any thoughts, ideas, or help would be greatly appreciated.

    Thanks in advance

    # July 22, 2009 at 11:01 am

    try this little gem

    http://www.htaccesseditor.com/en.shtml#a_errorPage

    # July 22, 2009 at 3:37 pm
    "ikthius" wrote:

    Great little resource, but it didn’t have RewriteRule’s. It only had Redirect and I’d like to not have to write a Redirect for each url.

    Thanks for the tip

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".