.htaccess重定向问题,带有多个.htaccess文件
我在下面使用的.htaccess文件将www重定向到我的public_html目录上的non www,
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
它的工作正常和重定向如下,
www.example.com
to
https://example.com
在我的子目录中,称为最新的sub Directory,我有另一个.htaccess文件,
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L]
如下
www.example.com/latest/index.php?page=1
to
www.example.com/latest/1
现在 即使我在主目录中都有.htaccess文件,该文件将www www www,我的这个目录也不会将www重定向到非www。
我想重定向
www.example.com/latest/1
to
https://example.com/latest/1
我确定我的目录中的.htaccess文件会引起问题,但我不知道如何解决。让我知道这里是否有人可以帮助我。
谢谢!
I am using .htaccess file like below for redirect www to non www on my public_html directory
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
its working fine and redirect like below
www.example.com
to
https://example.com
Now in my sub directory called latest, I have another .htaccess file like below
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L]
which is making my url clean like below
www.example.com/latest/index.php?page=1
to
www.example.com/latest/1
but even I have .htaccess file in home directory which is making www to non www, my this directory does not redirect www to non www.
I want redirect
www.example.com/latest/1
to
https://example.com/latest/1
I am sure .htaccess file in my directory is causing issue but I do not know how to resolve it. Let me know if anyone here can help me for the same.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是,
mod_rewrite
没有继承(至少默认情况下)。如果您在“默认”目录中有一个重写规则。.您将必须在下面的所有后续目录中包含该规则。我从未见过(或听说过)允许mod_rewrite
允许从父.htaccess
文件继承的设置。通常,这只是被认为是“它的方式”。更新
这个问题在服务器故障中也解释了这一点。
mod_rewrite
从上一个htaccess
文件中的规则甚至没有处理。将2组结合在子目录中
The problem is,
mod_rewrite
is not inherited (at least by default). If you have a rewrite rule in the "default" directory .. You're going to have to include that rule in all subsequent directories "below" that. I have never seen (or heard of) a setting for allowingmod_rewrite
to allow inheritance from parent.htaccess
files. In general, this is just accepted as "the way it is".UPDATE
THIS QUESTION In Server Fault explains this as well. The
mod_rewrite
rules from the previoushtaccess
files don't even get processed.COMBINE THE 2 in the SUB DIRECTORIES