次のような URL をどのように書き換えますか。
http://www.site.com/sub-directory/page-name
に
http://www.site.com/page-name
?
次のような URL をどのように書き換えますか。
http://www.site.com/sub-directory/page-name
に
http://www.site.com/page-name
?
意図したソリューションはVirtual Hostsを使用していると思いますが、httpd.conf にアクセスできない場合は、次の書き換えルールを試すことができます。
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} =host1.example.com
RewriteCond %{REQUEST_URI} !^/host1-dir
RewriteRule ^(.*) host1-dir/$1 [L]
RewriteCond %{HTTP_HOST} =host2.example.com
RewriteCond %{REQUEST_URI} !^/host2-dir
RewriteRule ^(.*) host2-dir/$1 [L]
RewriteCond %{HTTP_HOST} =host3.example.com
RewriteCond %{REQUEST_URI} !^/host3-dir
RewriteRule ^(.*) host3-dir/$1 [L]
# If doesn't match any of it then 404 Not Found or anything you like
RewriteCond %{HTTP_HOST} =host1.example.com
RewriteCond %{HTTP_HOST} =host2.example.com
RewriteCond %{HTTP_HOST} =host3.example.com
RewriteRule .* - [R=404,L]
IIRC mod_rewrite は正規表現をサポートしているため、次の置換を使用できます。
^(.*/)[^/]*&
括弧は last まですべて一致し/
ます。
次に、グループ参照を使用して再利用します$1
。残りはドロップされます。
regexp の使用方法については、mod_rewrite のヘルプを確認してください。