2012-02-07 7 views
0

でスラッシュなしで、私は「ディスプレイ - 」で始まるファイルをたくさん持っている、のように:私は(他の接頭辞を持つファイルがあるとして)組織のためにそれらの名前を維持したい% REQUEST_URIの.htaccess

display-profile.php 
display-photos.php 
display-comments.php 
... 

が、私は自分のURLから "display-"を削除したい。
display-%{REQUEST_URI}がファイルであるかどうかを確認するために.htaccessを使用するつもりでしたが、その環境変数の先頭にスラッシュ「/」が付きます。

最初にスラッシュのない%{REQUEST_URI}を取得するにはどうすればよいですか?または、これを確認する他の方法はありますか?

ありがとうございます。私はLinux上でApacheを使用しています。

答えて

2
RewriteEngine on 
RewriteBase/
RewriteCond %{DOCUMENT_ROOT}/display-$1 -f 
RewriteCond %{REQUEST_URI} !display-([^/]+).php$ 
RewriteRule ([^/]+)$ display-$1 [L,QSA] 

あるいは、別のオプション:

RewriteEngine on 
RewriteCond %{REQUEST_URI} .(.+)$ 
RewriteCond %{DOCUMENT_ROOT}/display-%1 -f 
RewriteRule . display-%1 [L,QSA] 

おそらく短い:

RewriteEngine on 
RewriteBase/
RewriteCond %{DOCUMENT_ROOT}/display-$1 -f 
RewriteRule ^(.+)$ display-$1 [L,QSA] 

あるいは:

RewriteEngine on 
RewriteCond %{DOCUMENT_ROOT}/display-$1 -f 
RewriteRule ^/?(.+)$ display-$1 [L,QSA] 
関連する問題