.htaccess - 以不同的方式处理 htaccess apache 中的 2 个类似 url
问题描述
大家好,我需要有关 apache htaccess 的帮助。我有这 2 个网址:
- 测试 / en / guns2 / beretta/
- 测试 / en / 1564 / vibram-beretta-m9a3/
我如何以不同的方式捕捉这两种情况?
实际上我有这个htaccess:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/test/admin[NC]
RewriteCond %{REQUEST_URI} !^/test/(it|en) [NC]
RewriteRule ^(.*)$ /test/en/$1 [R=301,L,QSA]
RewriteRule ^([\w-]+)/([\w-]+)/(\d+)/([\w-]*)$ /test/index.php?detMod=$3 [L,QSA,NC]
RewriteRule ^([\w-]+)/([\w-]+)/([\w-]+)/([\w-]*)$ /test/index.php?page=$2&category=$3 [L,QSA,NC]
但是对于数字(1564)而不是(guns2)的情况,我需要另一条规则
解决方案
用于\d+
仅匹配数字并[\w-]+
用于匹配字母数字,_
以及-
:
^([\w-]+)/([\w-]+)/(\d+)/([\w-]*)$
和
^([\w-]+)/([\w-]+)/([\w-]+)/([\w-]*)$
建议的.htaccess:
RewriteCond %{REQUEST_URI} !^/test/admin[NC]
RewriteCond %{REQUEST_URI} !^/test/(it|en) [NC]
RewriteRule ^(.*)$ /test/en/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([\w-]+)/([\w-]+)/(\d+)/([\w-]*)$ test/index.php?detMod=$3 [L,QSA,NC]
RewriteRule ^([\w-]+)/([\w-]+)/([\w-]+)/([\w-]*)$ test/index.php?page=$2&category=$3 [L,QSA,NC]
推荐阅读
- javascript - 如何在 mapbox gl js 中的 wms 图层示例上添加鼠标移动事件?
- java - JavaFx 自定义 ListCell 为空
- java - Spring Java 8 项目,REST DOCS,无法创建目录
- c# - 如何使用c#一一读取db表列数据
- java - 在 JAXB 中,如何将节点值设置为字符串字段的属性值?
- python - 如何在pandas / python中将多个数据框obj合并为一个具有给定条件的数据框obj
- android - 如何增加 Android 调试器超时
- python - 在 python 中从 MATLAB 的 union 复制索引输出
- html - 屏幕阅读器未阅读自定义下拉菜单的选项
- python - Django 在夹具拆解中测试 IntegrityError