Htaccessで3つのサブディレクトリレベルを管理するにはどうすればよいですか?
説明:
http://example.com/category1/
http://example.com/category2/
http://example.com/category3/
RewriteRule to *category.php?category=$1*
http://example.com/category1/type1/
http://example.com/category2/type7/
http://example.com/category3/type8/
RewriteRule to *type.php?category=$1&type=$2*
http://example.com/category1/type1/company3/
http://example.com/category2/type7/company4/
http://example.com/category3/type8/company9/
RewriteRule to *company.php?category=$1&type=$2&company=$3*
.htaccessファイルは最初のルートフォルダ(index.php)にあります
次は最善の方法ですか?
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/.]+)(?:/)?$ /category.php?category=$1 [L]
RewriteRule ^([^/.]+)/([^/.]+)(?:/)?$ /type.php?category=$1&type=$2 [L]
RewriteRule ^([^/.]+)/([^/.]+)/([^/.]+)(?:/.*)?$ /company.php?category=$1&type=$2&company=$3 [L]
あなたはかなり近いです。これRewriteCond
は次の即時にRewriteRule
のみ適用されるため、チェックは!-f
最初のルールにのみ使用されることに注意してください。既存のファイルとディレクトリに対するすべてのリクエストを破棄する別のルールを設定できます。
RewriteEngine On
# skip all files and directories from rewrite rules below
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^([\w-]+)/?$ category.php?category=$1 [L,QSA]
RewriteRule ^([\w-]+)/([\w-]+)/?$ type.php?category=$1&type=$2 [L,QSA]
RewriteRule ^([\w-]+)/([\w-]+)/([\w-]+)/?$ company.php?category=$1&type=$2&company=$3 [L,QSA]
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加