开发者

Help rewriting urls

So what I am tr开发者_如何转开发ying to do is create a website where the index.php will piece all the pages together with based upon parameters sent by query string.

I want to "rewrite" the urls from the form: http://example.com/index.php?p=cat1/page1 to something like http://example.com/cat1/page1

I am attempting to make use of .htaccess mod_rewrite rules, but have been unable to make anything work.

I know there are mountains of info on this stuff.. I have spent a few hours already reading about it and tinkering, but I feel stuck. Nothing I am doing seems to yield any results.

Mod_rewrite IS loaded on the server (says phpinfo())

My .htaccess code:

RewriteEngine On
RewriteRule ^/([home|cat1|cat2]/)?([a-zA-Z]+_?)*/?$ /index.php?p=$1/$2 [L]

My index.php code:

<?php 

if (isset($_GET["p"])){
    $page = htmlspecialchars($_GET["p"]);
}else{
    $page = "home";
}

include('./template/header.php');

if (is_dir("./pages/$page")){
    include("./pages/$page/overview.php");
}else{
    if (file_exists("./pages/$page.php")){
        include("./pages/$page.php");
    }else{
        //not found
        echo '<h1 id="pageNotFound">Page Not Found</h1>';
    }
}
include('./template/footer.php');

?>


Here's your .htaccess fix:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !\.(jpg|jpeg|gif|png|css|js|pl|txt)$
RewriteRule ^(home|services)/([a-zA-Z_\-]+)(\/?)$ /NEP2/index.php?p=$1/$2 [NC,QSA,L]

About the PHP, can you move the pages below the public_html folder?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜