2011-12-09 8 views
0

/productsディレクトリに古いコンテンツがたくさんある状況があります。前進すると、新しいコンテンツは/ productフォルダに入れられます。ファイルやディレクトリが存在しない場合、/ productにリダイレクトします。.htaccessファイルまたは第2レベルのディレクトリが存在しない場合のリダイレクト

I /製品フォルダ内の.htaccessファイルに以下があります。

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ /product/$1 [R=301,L] 

これは/製品ディレクトリ内のファイルとのindex.htmファイルや他のファイル名を含むサブディレクトリに適しています、 -

/製品/ someproduをリダイレクトしないでください

/製品/ someproduct:しかし、私は2つのレベルであることを非既存のディレクトリにリダイレクトを制限したいのですがct/anotherproduct /product/someproduct/anotherproductにリダイレクトする

2レベル以上の深さのサブディレクトリにのみルールを適用するにはどうすればよいですか?

答えて

0

RewriteEngine On 
RewriteBase/

#for all /products/somefolder/any_folder_level_deeep content 
RewriteCond %{REQUEST_URI} ^/products/([^/]+/.+)$ [NC] 
#if file does not exist 
RewriteCond %{REQUEST_FILENAME} !-f 
#and directory does not exist 
RewriteCond %{REQUEST_FILENAME} !-d 
#redirect to product folder 
RewriteRule . /product/%1 [R=301,L] 
次のことを試してみてください
関連する問題