I have the following lines in my .htaccess
file in a directory called blog.
我在我的。htaccess文件中有以下几行在一个名为blog的目录中。
RewriteCond %{HTTPS} on
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Different things happen when I do the following:
当我做以下事情时,会发生不同的事情:
https://staging.example.com/blog/ - redirect does not work
https://staging.example.com/blog - redirect does work
When a trailing slash exists my redirect does not work, why is that the case?
当一个斜线存在时,我的重定向不起作用,为什么会这样?
Update
更新
This is the blog/.htaccess file.
这是博客/。htaccess。
<IfModule mod_rewrite.c>
RewriteEngine On
# Froce HTTP
RewriteCond %{HTTPS} on
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
2 个解决方案
#1
2
https://staging.example.com/blog/ - redirect does not work
https://staging.example.com/blog/ - redirect不能工作
This could be due a presence of blog/.htaccess
. If that is true then add this line on top of other rules there as well:
这可能是因为blog/.htaccess的存在。如果这是真的,那么在其他规则之上加上这一行:
RewriteEngine On
RewriteCond %{HTTPS} on [OR]
RewriteCond %{HTTP:X-Forwarded-Proto} https
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#2
1
If you have a catalog with name equal to the redirect "path", it has more priority than your rule.
如果您有一个名称与重定向“路径”相同的目录,那么它比您的规则具有更多的优先级。
In your case, if you have a "blog" directory under DocumentRoot, redirecting simply fails.
在您的示例中,如果在DocumentRoot下有一个“blog”目录,那么重定向就会失败。
We need more informaction about your structure and other rules.
我们需要更多关于你的结构和其他规则的信息。
But I've not been sleeping for a bunch of nights because of existing directory which prevented my rewriting rules.
但是我已经有好几个晚上没有睡觉了,因为现有的目录阻止了我的重写规则。
#1
2
https://staging.example.com/blog/ - redirect does not work
https://staging.example.com/blog/ - redirect不能工作
This could be due a presence of blog/.htaccess
. If that is true then add this line on top of other rules there as well:
这可能是因为blog/.htaccess的存在。如果这是真的,那么在其他规则之上加上这一行:
RewriteEngine On
RewriteCond %{HTTPS} on [OR]
RewriteCond %{HTTP:X-Forwarded-Proto} https
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#2
1
If you have a catalog with name equal to the redirect "path", it has more priority than your rule.
如果您有一个名称与重定向“路径”相同的目录,那么它比您的规则具有更多的优先级。
In your case, if you have a "blog" directory under DocumentRoot, redirecting simply fails.
在您的示例中,如果在DocumentRoot下有一个“blog”目录,那么重定向就会失败。
We need more informaction about your structure and other rules.
我们需要更多关于你的结构和其他规则的信息。
But I've not been sleeping for a bunch of nights because of existing directory which prevented my rewriting rules.
但是我已经有好几个晚上没有睡觉了,因为现有的目录阻止了我的重写规则。