この「Apache mod_rewrite Introduction」を読むことを強くお勧めします
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.*)\.php [NC]
RewriteRule ^ /%1 [R=301,QSA,L]
# Redirect to hello
RewriteRule ^marketplace$ /hello [R=301,NC,L]
# Show the content of marketplace on hello
RewriteRule ^hello$ /marketplace.php [NC,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f
RewriteRule ^([^/]+)/?$ $1.php [L]
上記は、完全にテストされ、機能するルールです。
最初のルールは.php、URL のようなディレクトリにリダイレクトされます。たとえば、domain.com/marketplace.phpになりdomain.com/marketplaceます。
2 番目のルールは にリダイレクトさmarketplaceれhelloます。
3 番目のルールは に内部的にリダイレクトさhelloれるmarketplace.phpため、URL はhelloのコンテンツのままになりますmarketplace.php。
最後のルールは、ディレクトリが存在しないことを確認しますが、php ファイルとして存在し、内部的にそこにリダイレクトします。
したがって、アクセスmarketplace.phpするとmarketplacethenhelloに移動し、hello から のコンテンツが表示されますmarketplace.php。
marketplace.php存在しない場合は、404 エラーが発生します。