htaccess:使用索引参数重写无法正常工作
htaccess: rewriting with index parameter doesn't work properly
好吧,所以我现在真的很挣扎,我已经尝试了一切,阅读了文章和教程,但我仍然不知道为什么这不起作用。
我有一个 index.php 文件:
echo "some test";
if(isset($para)) {
include $para . '.php';
} else {
echo "there's no parameter";
}
因此,如果用户查看带有参数 'home' (http://mypage.com/test/index.php?para=home) 的页面,他将获得正确的页面。确实有效。
.htaccess:
DirectoryIndex index.php
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mypage.com$ [NC]
RewriteRule ^(.*)$ http://mypage.com/test/ [R=301,L]
RewriteBase /test/
RewriteRule ^([a-z]+)$ index.php?para=
但是当我尝试使用重写的 link (http://mypage.com/test/home) 进行导航时,浏览器只输出 包含的文件 并且它完全忽略了 index.php及其内容.
我的 htaccess 文件有问题吗?还是我需要更改一些服务器配置?因为我在不同的网络服务器上有不同的 htaccess 文件,而且它没有任何问题。但它在我现在使用的网络服务器上不起作用(遗憾的是,我只能访问 htdocs 文件夹)。
编辑: 刚刚检查了 phpinfo,页面是 运行 on PHP 5.3.28 on apache2.
已解决!
问题已解决。添加 'Options -Multiviews' 解决了问题。
这里的提示是:
The browser only outputs the included file and it completely ignores
the index.php and its content.
尝试在您想要使用 mod_rewrite 进行此重新映射的上下文中以及在您的脚本中禁用 mod_negotiation(选项 - 多视图)。
mod_negotiation 是最常见的原因 "other" 似乎正在对您的资源进行重写。
好吧,所以我现在真的很挣扎,我已经尝试了一切,阅读了文章和教程,但我仍然不知道为什么这不起作用。
我有一个 index.php 文件:
echo "some test";
if(isset($para)) {
include $para . '.php';
} else {
echo "there's no parameter";
}
因此,如果用户查看带有参数 'home' (http://mypage.com/test/index.php?para=home) 的页面,他将获得正确的页面。确实有效。
.htaccess:
DirectoryIndex index.php
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mypage.com$ [NC]
RewriteRule ^(.*)$ http://mypage.com/test/ [R=301,L]
RewriteBase /test/
RewriteRule ^([a-z]+)$ index.php?para=
但是当我尝试使用重写的 link (http://mypage.com/test/home) 进行导航时,浏览器只输出 包含的文件 并且它完全忽略了 index.php及其内容.
我的 htaccess 文件有问题吗?还是我需要更改一些服务器配置?因为我在不同的网络服务器上有不同的 htaccess 文件,而且它没有任何问题。但它在我现在使用的网络服务器上不起作用(遗憾的是,我只能访问 htdocs 文件夹)。
编辑: 刚刚检查了 phpinfo,页面是 运行 on PHP 5.3.28 on apache2.
已解决!
问题已解决。添加 'Options -Multiviews' 解决了问题。
这里的提示是:
The browser only outputs the included file and it completely ignores the index.php and its content.
尝试在您想要使用 mod_rewrite 进行此重新映射的上下文中以及在您的脚本中禁用 mod_negotiation(选项 - 多视图)。
mod_negotiation 是最常见的原因 "other" 似乎正在对您的资源进行重写。