【问题标题】:How to redirect page with htacces with URL parameter如何使用带有 URL 参数的 htaccess 重定向页面
【发布时间】:2020-10-29 05:48:48
【问题描述】:

我有一个保存 HTML 页面的文件夹。我将这些页面包含在 PHP 包含函数中。我在 index.php 中使用 URL 参数值调用这些页面,其中 URL 参数 xpage 等于保存在我的另一个文件夹中的页面名称,并且 index.php 保存在根文件夹中。

如果在另一个文件夹中找不到名为 HTML 页面的参数 xpage 值,我如何使用 htaccess 重定向到 404 页面?

http://example.com/about-me 其中about-me 是存在于我的另一个文件夹中的页面名称,即 about-me.html。 我想如果文件夹中不存在这个 about-me.html 然后将 URL 重定向到 URL http://example.com/404

我也想如果 url 参数是受欢迎的,home 和 index 然后删除它并转到主域 http://www.example.com

【问题讨论】:

  • 嗨,欢迎来到 SO!如果您提供一些代码来帮助诊断您的问题,将会很有帮助。

标签: php html .htaccess


【解决方案1】:

如果你包含一些代码会很有帮助,但我会猜测

你不需要为此使用 .htaccess

<?php
$file = "somefolder/" . $_GET["urlparm"] . ".html";

if ( file_exists( $file)  ) {
   include_once( $file  );
} else {
   http_response_code(404);
   include_once('somedefault404.php'); 
   die();
}

【讨论】:

  • 我也想如果 url 参数是受欢迎的,home 和 index 然后删除它并转到主域。
  • “主域”是什么意思?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-07-01
  • 1970-01-01
  • 2018-07-18
  • 1970-01-01
  • 2022-12-29
  • 2014-04-29
  • 1970-01-01
相关资源
最近更新 更多