我想从网址中删除子文件夹,并使用.htaccess
从网址获取网页名称。
假设我的真实目录结构是:
/public_html/promoted-content/gui/promoted-content.php
/public_html/promoted-content/pages.php
switch($_GET['pageName']) {
case 'home': {
include "gui/promoted-content.php";
break;
}
case 'promoted-content-news': {
$default_title = "News | ".$default_title;
include "gui/promoted-content.php";
break;
}
case 'promoted-content-news-details': {
$default_title = "News | ".$default_title;
include "gui/promoted_contentdetail.php";
break;
}
RewriteRule ^([A-Za-z0-9-]+)/?$ promoted-content/index.php?pageName=pages&id=$1 [NC,L] # Process Pagename requests
所以,我希望将网址www.example.com/promoted-content/gui/promoted-content.php?id=1
重新命名为:
www.example.com/promoted-content-news/pageid/pagetitle
答案 0 :(得分:0)
你需要在.htaccess中捕获3个参数,一个用于pageName,一个用于id,一个用于标题:
#make sure existing files and directories work
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/([0-9]+)/(.*)$ promoted-content/index.php?pageName=$1&id=$2&title=$3 [L]