所以我要做的是创建一个网站,其中index.php将基于查询字符串发送的参数将所有页面拼凑在一起。
我想从表单“http://example.com/index.php?p=cat1/page1”重写“http://example.com/cat1/page1
之类的网址我正在尝试使用.htaccess mod_rewrite规则,但一直无法正常工作。
我知道这些东西有很多信息。我已经花了几个小时阅读它并修修补补,但我感到困惑。我所做的一切似乎都没有产生任何结果。
服务器上加载了Mod_rewrite IS(phpinfo())
我的.htaccess代码:
RewriteEngine On
RewriteRule ^/([home|cat1|cat2]/)?([a-zA-Z]+_?)*/?$ /index.php?p=$1/$2 [L]
我的index.php代码:
<?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');
?>
答案 0 :(得分:2)
这是你的.htaccess修复:
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]
关于PHP,您可以将页面移动到public_html文件夹下吗?