我试图学习编辑 .htaccess,但我的第一个示例不起作用
我正在尝试在本地主机上学习 .htaccess 重写,我只是启用 mod_rewrite 并使用 phpinfo() 检查它;一切都很好
现在我创建了一个 php 文件:file1.php
<?php
echo "file one working successfully";
print_r($_GET);
?>
然后创建了第二个 php 文件:file2.php
<?php
echo "file two working successfully";
print_r($_GET);
?>
然后我创建了一个 .htaccess 文件并编写以下重写规则:
RewriteEngine on
RewriteRule ^file1.php$ file2.php
然后我输入了 url http://localhost/test/file1.php 我相信它应该重定向到 file2.php 但没有任何反应我类似地尝试了一些其他代码但是没用怎么办我摆脱了它。我在 ubuntu 10.04 上使用 apache 2 我启用了 mod_rewrite 并在 phpinfo 中检查了它一切都很好那么为什么我的示例不起作用我很沮丧帮助我离开这里。
提前致谢,
我的所有文件也都位于 test .htaccess 的同一目录中 我在 http://www.workingwith.me.uk/articles/scripting 找到这个例子/mod_rewrite 并按照建议进行操作,但似乎没有任何效果
i am trying to learn .htaccess rewrite on my localhost what i did just enable mod_rewrite and checked it with phpinfo(); everything is fine
now i create a php file : file1.php
<?php
echo "file one working successfully";
print_r($_GET);
?>
and then created a second php file: file2.php
<?php
echo "file two working successfully";
print_r($_GET);
?>
then i created an .htaccess file and write the following rewite rule :
RewriteEngine on
RewriteRule ^file1.php$ file2.php
then i typed url http://localhost/test/file1.php i believe it should redirect to file2.php but nothing happens i similarly i tried some other code but didnt work how can i get out of it. i am using apache 2 on ubuntu 10.04 i have enabled mod_rewrite and checked it in phpinfo everything is fine then why my example is not working i m frustrated help me to get out of here.
Thank in advance
i am having all my files in the same directory that is test .htaccess too
i find this an example at http://www.workingwith.me.uk/articles/scripting/mod_rewrite and followed as it suggested but nothing seems to work
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您的 .htaccess 文件位于根目录中,通过以下更改访问
http://localhost/test/file1.php
应该返回文件二工作成功
Assuming that your .htaccess file is in the root directory, with the change below accessing
http://localhost/test/file1.php
should give returnfile two working successfully
尝试
假设 htaccess 看到 .作为正则表达式命令,而不是实际的 .,您需要反斜杠吗?
Try
Assuming htaccess sees . as a regex command, not as an actual ., you need to backslash it?