我有一个奇怪的问题,只发生在我的 Mac 上(我没有在另一台 Mac 上尝试,但在 linux 上试过,它可以工作)
这是我的 .htaccess
RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php?key=$1
在我的 index.php 上,我放了:
echo $_GET['url'];
如果我的网址是这样的,它将返回一个空数组:
本地主机/测试/索引/xpto
但如果我把它放在 url 中,它会返回 'index2/xpto':
本地主机/测试/index2/xpto
所以问题出在字符串索引上。
你们知道为什么它在我的mac上不起作用,但在linux上却可以吗?
我在 mac os x lion 上使用标准 apache。我只是在 httpd.conf 上更改此行
<Directory />
Options FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
</Directory>
....
<Directory "/Library/WebServer/Documents">
AllowOverride All
...
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
已编辑
通过工作,我的意思是 $_GET['key'] 不是空的。并显示我在浏览器中输入的网址。
但是当我在浏览器上使用这个网址时:
http://127.0.0.1/test/index/xpto
我的 $_GET['key'] 是空的
如果我使用这个网址:
http://127.0.0.1/test/anythingbutindex/xpto
$_GET['key'] 有文本:anythingbutindex/xpto
我确实在我的 Mac 上安装了 XAMPP,并且这段代码在 index.js 上运行良好。所以问题出在我 MAC 上的默认 apache 上。
谢谢。