RewriteCond REQUEST

编程入门 行业动态 更新时间:2024-10-12 22:25:34
本文介绍了RewriteCond REQUEST_URI-^不能按预期工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在codeigniter中建立一个站点.我有一系列重写条件& .htaccess文件中的规则.第一组规则根据uri的第一段打开或关闭SSL.

I'm building a site in codeigniter. I have a series of rewrite conditions & rules in the .htaccess file. The first set of rules turns SSL on or off depending on the first segment of the uri.

然后再次循环遍历&如果找到匹配项,则适当地重定向页面.如果没有匹配项,并且uri不以列出的任何字符串开头,它将您重定向到另一个页面.如果不满足任何条件,则转到索引页面.

Then it loops through again & if it finds a match, redirects the page appropriately. If there is no match, and the uri does NOT start with any of the strings listed, it redirects you to another page. If no conditions are met, it goes to the index page.

问题出在我第一组打开SSL的规则上,离开.我想指定uri必须以admin或secure开头.但是,如果将^添加到字符串的开头,则一切都会中断.这就是我所拥有的:

The problem is with my first set of rules that turn SSL on & off. I want to specify that the uri must START with admin or secure. But if I add the ^ to the beginning of the string, everything breaks. Here's what I have:

RewriteCond %{HTTPS} off RewriteCond %{REQUEST_URI} ^/?(admin|secure) RewriteRule ^(.*)$ %{HTTP_HOST}/$1 [R=301,L] RewriteCond %{HTTPS} on RewriteCond %{REQUEST_URI} !^/?(admin|secure) RewriteRule ^(.*)$ %{HTTP_HOST}/$1 [R=301,L] ...specific rewrites here RewriteRule ^secure-form1$ secure/contract/secure-form1 [L] RewriteRule ^secure$ secure/article/secure [L] RewriteCond %{HTTP_HOST} ^www.example$ RewriteCond %{REQUEST_URI} !^/(admin|form|secure|page)/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/page/article/$1 [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L]

如果我在前两个重写条件(https打开和关闭)中保持^符号,则 www.example/secure 重写为 www.example/index.php/secure/article/secure 这是最后的重写规则.网址实际上在浏览器中更改为该网址.

If I keep the ^ symbol in the first 2 rewrite conditions (https on & off) then www.example/secure rewrites to www.example/index.php/secure/article/secure which is the last rewrite rule. The url actually changes to this in the browser.

如果我从前两个重写条件中删除了^符号,那么它将转到右页.但是,我确实需要指定uri的开头,因为在uri的中间(以及斜杠后面)还有其他安全"的页面不应该使用SSL.

If I take the ^ symbol out of the first 2 rewrite conditions, then it goes to the right page. But I do need to specify the beginning of the uri because there are other pages that have "secure" in the middle of the uri (and following a slash) that should NOT use SSL.

我无法弄清楚这一点.

推荐答案

尝试以下方法:

RewriteCond %{HTTPS} off RewriteCond %{HTTP_HOST} ^(.*)$ RewriteRule ^/?(admin|secure)$ %1/$1 [R=301,L]

更多推荐

RewriteCond REQUEST

本文发布于:2023-10-31 13:34:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546236.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:RewriteCond   REQUEST

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!