1

私はhtaccessを介して次のことを行う方法を見つけようとしています。

  1. (.php)拡張子を削除します
  2. 末尾のスラッシュを削除します(/)
  3. 以前の(.php)ページを非phpページにリダイレクトします
  4. ルートインデックスのすべてのトレースをルートドメインにリダイレクトします

ディレクトリ構造の例を次に示します。

"http://example.com" (canonical - this is what I want)
"http://example.com/index" (redirect or 404)
"http://example.com/index/" (redirect or 404)
"http://example.com/index.php" (redirect or 404)
"http://example.com/index.php/" (redirect or 404)

"http://example.com/about" (canonical - this is what I want)
"http://example.com/about/" (redirect or 404)
"http://example.com/about.php" (redirect or 404)
"http://example.com/about.php/" (redirect or 404)

アップデート:

これは私の現在の構成のように見えます。phpを使用して正規リンクを委任し、リダイレクト/表示404を実行します。問題が見つかった場合、またはより良い解決策を提供できる場合は、本当に感謝します。現在、以下のコードは機能します。各phpファイルに、ページに固有の独自の正規リンク関数を指定します。次に、関数は現在のページが正規のページと同じであるかどうかを認識し、そうでない場合はエラーをスローし、目的のページだけがコンテンツにアクセスできるようにします。

ErrorDocument 404 /404.php

RewriteEngine On
#removes trailing slash
RewriteCond %{HTTP_HOST} ^localhost:8888$
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

#removes php extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

<?php

function resolve_canonical($canonical,$location = "404"){
  $current_url= "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
  if($current_url !== $canonical){
    if($location == "404"){
      //header("location: http://".$_SERVER['HTTP_HOST']."/404");
      //header("HTTP/1.0 404 Not Found");
      readfile('404.php');
      exit();      
    }elseif($location == "redirect"){
       header("location: ".$canonical);          
       exit();  
     }
  }
}

?>
4

1 に答える 1

1

%{REQUEST_URI}優先URLでない場合は、301リダイレクトを調べて実行します。また、検索エンジンについては、正規のメタタグを確認してください。

于 2011-07-28T00:36:52.490 に答える