gpt4 book ai didi

php - 子目录的mod_rewrite

转载 作者:可可西里 更新时间:2023-11-01 00:26:01 25 4
gpt4 key购买 nike

我有一个域和一个名为“sub”的子文件夹。在“sub”中是 index.php,其中包含:

$page = $_GET['page'];
switch ($page)
{
case "main":
echo "main";
break;
case "task_orders":
echo "task_orders";
break;
case "team_members":
echo "team_members";
break;
case "team_experience":
echo "team_experience";
break;
case "quality_assurance":
echo "quality_assurance";
break;
case "geographical_support":
echo "geographical_support";
break;
case "contact":
echo "contact";
break;
default:
echo "main";
}

我在“sub”中的 htaccess 是:

Options +FollowSymLinks
RewriteEngine On

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

当我点击一个看起来像这样的链接时:

<li><a href="/sub/main" title="Main" class="current">Main</a></li>
<li><a href="/sub/task_orders" title="Task Orders">Task Orders</a></li>
<li><a href="/sub/team_members" title="Team Members">Team Members</a></li>
<li><a href="/sub/team_experience" title="Team Experience">Team Experience</a></li>
<li><a href="/sub/quality_assurance" title="Quality Assurance Program">Quality Assurance</a></li>
<li><a href="/sub/geographical_support" title="Geographical Support">Geographical Support</a></li>
<li><a href="/sub/contact" title="Points of Contact">Points of Contact</a></li>

我得到一个未找到的页面而不是回显我所在的页面,有什么想法吗?

我也试过:

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

同样的结果

最佳答案

你快到了。您不想在编写 RewriteRule 时指定前导 /

在文档根目录中:

RewriteEngine on
RewriteRule ^sub/([^/\.]+)/?$ /sub/index.php?page=$1 [L]

来自/sub 文件夹:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L]

关于php - 子目录的mod_rewrite,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6668423/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com