我试图从网址末尾删除字符串:
例如我有这样的结构:
http://sitename.com/category/first-category-name.php/?post_type=question
http://sitename.com/category/second-category-name.php/?post_type=question
http://sitename.com/category/...-category-name.php/?post_type=question
我想从网址末尾的http://sitename.com/category/-----category-name/?post_type=question to http://sitename.com/category/-----category-name/post_type/question
转换网址。
答案 0 :(得分:1)
如果查询字符串中存在post_type
值,则可以有条件地重定向。
// Get the category. This is here for example purposes.
$categoryName = 'first-category-name';
if (!empty($_GET['post_type'])) {
$postType = $_GET['post_type'];
header("Location: http://sitename.com/category/$categoryName/post_type/$postType", true, 301);
}
为了安全起见,您可能希望确保清除$category
和$postType
。