例を見てみましょう。
現在のURLはですhttp://domain.com/myurl
。これは、http://domain.com/index.php?p=myurl
この種類のhtaccessを使用してこのページのバニティURLを追加できることを示しています。
RewriteEngine On
RewriteBase /
RewriteRule ^myvanityurl/?$ myurl [L,R=301]
RewriteRule ^([a-zA-Z0-9-]+)/?$ index.php?p=$1 [L]
次に、http://domain.com/myvanityurl
にリダイレクトしますhttp://domain.com/myurl
このリダイレクトを透過的にしたい場合(別名、myvanityurl
URLバーに保持)、R=301
ルールからタグを削除します。
編集
編集後、これはあなたが探しているものです:
RewriteEngine On
RewriteBase /
RewriteRule ^([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)$ index.php?p=$1&profile=$2 [L]
RewriteRule ^([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/$ index.php?p=$1&profile=$2 [L]
次に、http://domain.com/edit/756
にリダイレクトしますhttp://domain.com/index.php?p=edit&profile=756
このコードは次のように簡略化できます。
RewriteEngine On
RewriteBase /
RewriteRule ^([\w-]+)/([\w-]+)/?$ index.php?p=$1&profile=$2 [L]