我在设置重定向时遇到了问题。我在某些目录中有索引页,目录名称是简单的六个字符长的标记,如ABCDEF。名称是字母数字和全部大写字母。我最初想要的是将包含令牌的所有流量,小写和大写指向正确的目录。 我没有访问服务器模块,如mod_speling,因此我使用php脚本来做实际的url重写。有用。 但后来我想添加一个步骤,直接所有的流量,如:.htaccess有条件重写/重定向
example.com/ABCDEF
example.com/abcdef
example.com/reference/abcDEF
example.com/referENces/ABCdeF
到以下目录:
example.com/references/ABCDEF/
我不能让这些工作,我得到重定向在循环中的所有时间。
我有我的htaccess什么:
# takes care of: example.com/abcdef
RewriteCond %{DOCUMENT_ROOT}/references/%{REQUEST_URI} !-d
RewriteCond %{REQUEST_URI} ^(/?)([a-zA-Z0-9]{6})(/?)$
RewriteRule ^(/?)([a-zA-Z0-9]{6})(/?)$ example.com/rewrite.php?rewrite=example.com%{REQUEST_URI} [QSA,L,NC,R=302]
# takes care of example.com/reference/abcDEF
RewriteCond %{REQUEST_URI} ^(/?)([REFNCS?refncs?]{9})/([a-zA-Z0-9]{6})(/?)$
RewriteRule ^(/?)([REFNCS?refncs?]{9})/([a-zA-Z0-9]{6})(/?)$ example.com/rewrite.php?rewrite=example.com%{REQUEST_URI} [QSA,L,NC,R=302]
# this should take care of: example.com/references/abcDEF , but if I uncomment it, we end up in a loop
#RewriteCond %{REQUEST_URI} ([REFNCSrefncs]{10})/([a-zA-Z0-9]{6})(/?)$
#RewriteRule ([REFNCSrefncs]{10})/([a-zA-Z0-9]{6})(/?)$ example.com/rewrite.php?rewrite=example.com%{REQUEST_URI} [QSA,L,NC,R=302]
# Finally this handles: example.com/ABCDEF
RewriteCond %{DOCUMENT_ROOT}/references/%{REQUEST_URI} -d
RewriteCond %{REQUEST_URI} ^(/?)([a-zA-Z0-9]{6})(/?)$
RewriteRule ^(/?)([a-zA-Z0-9]{6})(/?)$ example.com/references%{REQUEST_URI} [QSA,L,NC,R=302]
在这一点上,我相信一定有一个更好的,更普遍的正则表达式的解决方案。第二块和第三块可以以某种方式合并。
彼得
为什么这些不同的'[REFNCS?refncs?] {9}'和'[REFNCSrefncs] {10}' –
确实,第一个不需要s和S. –