0

URLを変更せずに、すべてのhtmlまたはphp URLにindex.phpを表示します

元。ユーザー タイプの anything-everything.html(.php) は、URL を変更せずに index.php を表示します。

状態 - ホストに any-everything.html(.php) が存在しない

URLを変更せずに404リダイレクトのように

4

2 に答える 2

1

SOへようこそ。Web サイトを Apache Web サーバーで実行している場合は、Apache モジュール mod_rewriteを使用してこれを実現できます。.htaccessWeb サイトのルートに配置する必要があるファイルの例を次に示します。

# switch on mod_rewrite
RewriteEngine On

# redirect all non-www request to www
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# rewrite all physical files and folders
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d

# add all exceptions that should not be redirected
RewriteCond %{REQUEST_URI} "/layout/" [OR]
RewriteCond %{REQUEST_URI} "/javascript/" [OR]
RewriteCond %{REQUEST_URI} "/content"

# and finally pass everything to the index.php as a parameter
RewriteRule .* - [L]
RewriteRule (.*) index.php?value=$1 [QSA]

これにより、次のことが行われます。

  • ユーザーがhttp://domain.comを要求すると、http://www.domain.com に転送されます
  • リクエストdomain.com/hello/world.htmlは index.php ファイルで終了し、既存の$_GET['value']を保持しhello/world.html、さらに処理することができます
于 2013-10-23T07:15:33.143 に答える
0

Apache rewrite を使用します (Apache を使用していて、サーバーにアクセスできる場合)。index.php へのすべてのパスを書き換える Apacheからのレシピは問題ないはずです。

于 2013-10-23T07:03:18.727 に答える