1

我正在尝试将所有 URL 重定向到https/feeds/. 这是一个 ExpressionEngine 站点,因此我还必须index.php从 URL 的开头删除。托管设置还要求?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.

我不明白为什么会这样。这是我所看到的事件过程:

  1. http://www.mysite.com/feeds/blog正在使用80端口,所以满足第一个条件

  2. http://www.mysite.com/feeds/blog以 开头/feeds/,因此它不满足下一个条件并退出规则

  3. http://www.mysite.com/feeds/blog不是文件或目录,因此满足接下来的 2 个条件。

  4. http://www.mysite.com/feeds/blog更改为http://www.mysite.com/index.php?/feeds/blog并循环回到顶部。

  5. http://www.mysite.com/index.php?/feeds/blog正在使用端口 80 并且它以 开头/index.php?/feeds/,因此它再次失败并退出规则

  6. http://www.mysite.com/index.php?/feeds/blog确实存在,因此它不符合接下来的 2 个条件并退出规则。

  7. 最终的服务器端 URL 是http://www.mysite.com/index.php?/feeds/blog,而客户端 URL 仍然是http://www.mysite.com/feeds/blog

这里发生了什么事?那段是?从哪里来的?

4

1 回答 1

0

试试这个更正的代码:

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]
于 2013-11-05T18:08:46.757 回答