.htaccess 重写规则添加?到URL
我正在尝试将所有URL重定向到.htaccess 重写规则添加?到URL,.htaccess,mod-rewrite,dynamic-url,.htaccess,Mod Rewrite,Dynamic Url,我正在尝试将所有URL重定向到https,以/feeds/开头的URL除外。这是一个ExpressionEngine站点,因此我还必须从URL的开头删除index.php。托管设置还要求?位于index.php的末尾。以下是我所拥有的: RewriteEngine On RewriteBase / # Force SSL for everything but feeds RewriteCond %{SERVER_PORT} 80 RewriteCond %{REQUEST_URI} !^/(i
https
,以/feeds/
开头的URL除外。这是一个ExpressionEngine站点,因此我还必须从URL的开头删除index.php
。托管设置还要求?
位于index.php
的末尾。以下是我所拥有的:
RewriteEngine On
RewriteBase /
# Force SSL for everything but feeds
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} !^/(index.php\?*/)*feeds/ [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$2 [R,L]
# Remove index.php from ExpressionEngine URLs
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
但是当我进入http://www.mysite.com/feeds/blog
,它将被重定向到https://www.mysite.com/?/feeds/blog
我不明白为什么会这样。以下是我所看到的事件过程:
http://www.mysite.com/feeds/blog
正在使用端口80,因此它满足第一个条件http://www.mysite.com/feeds/blog
以/feeds/
开头,因此它不满足下一个条件并退出规则http://www.mysite.com/feeds/blog
不是文件或目录,因此它满足以下2个条件http://www.mysite.com/feeds/blog
更改为http://www.mysite.com/index.php?/feeds/blog
并循环返回顶部http://www.mysite.com/index.php?/feeds/blog
正在使用端口80,它以/index.php?/feed/
开头,因此它再次失败该条件并退出规则http://www.mysite.com/index.php?/feeds/blog
确实存在,因此它无法满足接下来的2个条件并退出规则http://www.mysite.com/index.php?/feeds/blog
,客户端URL仍然是http://www.mysite.com/feeds/blog
这里发生了什么事?那个
段在哪里?
段来自哪里?试试这个更正后的代码:
RewriteEngine On
RewriteBase /
# Force SSL for everything but feeds
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !/feeds/ [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R,L,NE]
# Remove index.php from ExpressionEngine URLs
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /index.php?/$1 [L]
您能解释一下您所做的更改以及它们为什么会起作用吗?首先,您捕获了
$1
,但使用了$2
,然后在第二条规则中,您使用了*
而不是+
,我知道您为什么将$2
更改为$1
,但这不是为什么你把+
改成*
。首先,我认为你应该测试一下,看看它是否真的适合你。我可以回答你所有的问题,如果这是有效的:)测试<代码>http://mysite.com/feeds/blog被重定向到https://mysite.com/index.php?/feeds/blog
。