.htaccess 中的 RewriteRule 使所有字符串除了一些加载一个文件而其他字符串加载另一个文件
RewriteRule in .htacess to have all strings except some load one file and the other strings load another
这是我的 .htaccess 文件:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/ !-f
RewriteCond %{REQUEST_URI} /category1|category2|category3|category4/ [NC]
RewriteRule ^([^/]+)/?$ category.php?category= [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/ !-f
RewriteCond %{REQUEST_URI} (?!category1|category2|category3|category4) [NC]
RewriteRule ^([^/]+)/?$ article.php?slugId= [L]
我希望使用以下链接来加载具有相应类别参数值的 category.php
文件:
website.com/category1
website.com/category2
website.com/category3
website.com/category4
我希望 website.com/string
格式的其余字符串以字符串作为参数加载 article.php
文件。
每当我搜索任何类别时,它都能正常工作。但是,如果我搜索任何其他字符串,它会将我重定向回 index.php
根据您展示的示例和尝试,您能否尝试以下操作。请确保在测试您的 URL 之前清除您的浏览器缓存。
RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/ !-f
RewriteCond %{REQUEST_URI} (category1|category2|category3|category4) [NC]
RewriteRule ^([^/]+)/?$ category.php?category= [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/ !-f
RewriteCond %{REQUEST_URI} !(category1|category2|category3|category4) [NC]
RewriteRule ^([^/]+)/?$ article.php?slugId= [L]
这是我的 .htaccess 文件:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/ !-f
RewriteCond %{REQUEST_URI} /category1|category2|category3|category4/ [NC]
RewriteRule ^([^/]+)/?$ category.php?category= [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/ !-f
RewriteCond %{REQUEST_URI} (?!category1|category2|category3|category4) [NC]
RewriteRule ^([^/]+)/?$ article.php?slugId= [L]
我希望使用以下链接来加载具有相应类别参数值的 category.php
文件:
website.com/category1
website.com/category2
website.com/category3
website.com/category4
我希望 website.com/string
格式的其余字符串以字符串作为参数加载 article.php
文件。
每当我搜索任何类别时,它都能正常工作。但是,如果我搜索任何其他字符串,它会将我重定向回 index.php
根据您展示的示例和尝试,您能否尝试以下操作。请确保在测试您的 URL 之前清除您的浏览器缓存。
RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/ !-f
RewriteCond %{REQUEST_URI} (category1|category2|category3|category4) [NC]
RewriteRule ^([^/]+)/?$ category.php?category= [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/ !-f
RewriteCond %{REQUEST_URI} !(category1|category2|category3|category4) [NC]
RewriteRule ^([^/]+)/?$ article.php?slugId= [L]