この「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
するとmarketplace
thenhello
に移動し、hello から のコンテンツが表示されますmarketplace.php
。
marketplace.php
存在しない場合は、404 エラーが発生します。