如何更改默认目标网页网址

时间:2020-06-26 07:14:19

标签: url redirect url-rewriting

我想将着陆页网址从www.example.com/更改为www.example.com/index/id

我尝试过

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /example/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

Redirect 301 / http://example.com/index/id

RewriteRule ^index/([^/]*)$ ?i=page.index&lang=$1 [L]

</IfModule>

但不行。

请帮助我解决此问题。谢谢你。

1 个答案:

答案 0 :(得分:0)

要将URL从index.php重写为/index/id,您需要执行以下两个步骤:

  1. 在根目录中创建一个新文件(因此,仅在htdocs文件夹中),名称为.htaccess
  2. 复制以下代码,并将其粘贴到您之前创建的.htaccess文件中。
RewriteEngine On
RewriteRule ^index/id index.php [L]

但是其中存在一个问题,该代码仅允许您将所有流量从index.php重定向到新名称时,使用其他名称访问index.php,我建议您不要进行更改.htaccess文件中的文件只需检测URL文件中的当前index.php并根据需要将其重定向。

示例

<?
$actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
if(parse_url($actual_link, PHP_URL_PATH) != "/index/id"){
header('Location: /index/id');
}
else{
// do nothing 
}
?>

希望这对您有所帮助,谢谢?