[英]How to redirect page with htacces with URL parameter
我有一個文件夾,其中保存了 HTML 頁面。 我將這些頁面包含在 PHP 中,包括 function。 I am calling these pages in index.php with URL parameter value, where URL parameter xpage is equal to page name that are saved in my another folder & index.php is saved in root folder.
如果在另一個文件夾中找不到名為 HTML 頁面的參數 xpage 值,我如何使用 htaccess 重定向到 404 頁面?
http://example.com/about-me
其中about-me
是我的另一個文件夾中存在的頁面名稱 about-me.html。 I want if this about-me.html doesn't exist in folder then redirect URL to URL http://example.com/404
I also want if url parameter is welcome,home and index then remove it and go to main domain http://www.example.com
如果您包含一些代碼會有所幫助,但我會猜測
你不需要為此使用 .htaccess
<?php
$file = "somefolder/" . $_GET["urlparm"] . ".html";
if ( file_exists( $file) ) {
include_once( $file );
} else {
http_response_code(404);
include_once('somedefault404.php');
die();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.