我有一个域和一个子文件夹,名为“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]
和相同的结果
答案 0 :(得分:5)
你快到了。在撰写/
时,您不希望指定前导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]
答案 1 :(得分:2)
如果.htaccess位于子目录中,则不必在RewriteRule中写入完整路径。
所以在子目录中的.htaccess中使用它:
RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L]
或在root的.htaccess:
RewriteRule ^sub/([^/\.]+)/?$ sub/index.php?page=$1 [L]