.htaccess难以根据最终页面反斜杠';确定要使用哪个文件/';
我有两种类型的网页在我的网站的一部分 一个是类别,例如:.htaccess难以根据最终页面反斜杠';确定要使用哪个文件/';,.htaccess,.htaccess,我有两种类型的网页在我的网站的一部分 一个是类别,例如: example.com/section/fruit/ example.com/section/vegets/ 另一个用于查看页面详细信息,例如: example.com/section/fruit/apple example.com/section/fruit/orange example.com/section/fruit/grape 我使用.htaccess获取urlslug并与数据库对话,以显示正确的信息并使用正确的模板文件
- example.com/section/fruit/
- example.com/section/vegets/
- example.com/section/fruit/apple
- example.com/section/fruit/orange
- example.com/section/fruit/grape
RewriteCond %{REQUEST_URI} /section/(.*)/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule section/(.*)/ /template/category.php?urlslug=$1 [L]
RewriteCond %{REQUEST_URI} /section/(.*)/(.*)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule section/(.*)/(.*) /template/detail.php?category=$1&urlslug=$2 [L]
不幸的是,因为我有两种url显示方法,所以上面的.htaccess不起作用。对于类别,它们以“/”结尾,并且页面详细信息是打开的(没有斜杠),并且.htaccess文件无法确定要抓取哪一个
我想这里的问题是双重的
您可以使用以下规则:
# skip below rules for files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^section/([\w-]+)/?$ template/category.php?urlslug=$1 [L,NC,QSA]
RewriteRule ^section/([\w-]+)/([\w-]+)/?$ template/detail.php?category=$1&urlslug=$2 [L,QSA,NC]
请注意,
*
匹配所有内容。在正则表达式模式中使用锚允许您在/section/
之后只匹配一个路径组件。非常感谢您的帮助。非常感谢。