index.phpファイルがドキュメントルートにないようです(www私はそうだと思います)。そのため、.htaccessファイルからこれを行う方法はないと思います。ドキュメントルートの外部にアクセスするには、サーバー構成または仮想ホスト構成のいずれかでエイリアスを設定する必要があります。
# Somewhere in vhost/server config
Alias /index.php /var/www/path/to/index.php
# We need to make sure this path is allowed to be served by apache, otherwise
# you will always get "403 Forbidden" if you try to access "/index.php"
<Directory "/var/www/path/to">
Options None
Order allow,deny
Allow from all
</Directory>
これで、にアクセスできるようになります/var/www/path/to/index.php。/ var / www / path / toディレクトリ内の他のファイルは、それらを指すAlias(またはAliasMatchまたは)を作成しない限り安全であることに注意してください。URIを介してindex.phpScriptAliasにアクセスできるようになったので、ドキュメントルート(www)の.htaccessファイルにいくつかのmod_rewriteルールを設定して、index.phpを指すようにすることができます。/index.php
# Turn on the rewrite engine
RewriteEngine On
# Only apply the rule to URI's that don't map to an existing file or directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all requests ending with ".php" to "/index.php"
RewriteRule ^(.*)\.php$ /index.php [L]
これにより、 http://site/page1.phpをリクエストすると、ブラウザのアドレスバーは変更されませんが、サーバーは実際にサービスを提供します。/index.phpこれはにエイリアスされ/var/www/path/to/index.phpます。
必要に応じて、正規表現^(.*)\.php$をより適切なものに微調整できます。.phpこれは、を含む、で終わるものすべてに一致します/blah/bleh/foo/bar/somethingsomething.php。ディレクトリの深さを制限したい場合は、正規表現を^([^/]+)\.php$などに微調整できます。