我有PHP代码,可以显示文件夹中的页面:
<?php
error_reporting(0);
$page = $_GET['page'];
if (file_exists('help-pages/'.$page.'.php')) {
include('help-pages/'.$page.'.php');
} else {
echo "not found";
}
?>
我需要更改丑陋/help.php?page=somePage到/help/somePage。我读了很多关于mod_rewrite的文章,但对我没有帮助。
PS。抱歉我的英语不好:)
是的,可以使用mod_rewrite完成。将此代码放在DOCUMENT_ROOT/.htaccess
文件中:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^help/(.+?)/?$ /help.php?page=$1 [L,QSA,NC]
我喜欢使用CodeIgniter,因为它在URL 方面使用起来非常简单