.htaccess相同字词的重写规则

资料库


我有两个导致问题的规则:

RewriteRule ^posts$ posts.php
RewriteRule ^posts/create$ postscreate.php

我知道我可以使用“发布/创建”,但是这些只是所有同样问题中的两个规则。

我在本地主机(XAMPP)上完美地使用了此规则。

但是,一旦我将文件移动到主机上并访问了“ sub.domain.com/posts/create”,它会将我重定向到posts.php而不是postscreate.php。

为什么在localhost上不能正常工作,而在我的主机上却不能正常工作?我该如何解决?

我完整的.htaccess文件如下所示(仅使用两个规则):

AddType application/x-httpd-php .html
RewriteBase /
RewriteEngine On
RewriteCond %{SERVER_PORT} !=443
RewriteRule ^(.*)$ https://sub.domain.com/$1 [R=301,L]

Options -Indexes

RewriteRule ^posts$ posts.php
RewriteRule ^posts/create$ postscreate.php

本地主机上的.htaccess除https规则外完全相同。我也尝试在主机上使用没有https规则的.htaccess,但仍然无法正常工作。

阿努巴瓦

为什么在localhost上不能正常工作,而在我的主机上却不能正常工作?我该如何解决?

这很可能是由于MultiViews在Hoster上打开了该选项,但在localhost上关闭了该选项

要禁用此功能,请在.htaccess顶部使用以下行:

Options -MultiViews

选项MultiViews(请参阅http://httpd.apache.org/docs/2.4/content-negotiation.html)由Apache's content negotiation module运行前的选项 mod_rewrite使Apache服务器匹配文件扩展名。因此,如果/fileURL是URL,则Apache将提供服务/file.html

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章