我试图学习编辑 .htaccess,但我的第一个示例不起作用

发布于 2024-12-28 09:44:08 字数 962 浏览 2 评论 0原文

我正在尝试在本地主机上学习 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

來不及說愛妳 2025-01-04 09:44:08

假设您的 .htaccess 文件位于根目录中,通过以下更改访问 http://localhost/test/file1.php 应该返回文件二工作成功

RewriteEngine on
RewriteBase /

RewriteRule ^test/file1\.php$ file2.php [NC,L]

Assuming that your .htaccess file is in the root directory, with the change below accessing http://localhost/test/file1.php should give return file two working successfully

RewriteEngine on
RewriteBase /

RewriteRule ^test/file1\.php$ file2.php [NC,L]
苯莒 2025-01-04 09:44:08

尝试

RewriteEngine on
RewriteRule ^file1\.php$ file2.php

假设 htaccess 看到 .作为正则表达式命令,而不是实际的 .,您需要反斜杠吗?

Try

RewriteEngine on
RewriteRule ^file1\.php$ file2.php

Assuming htaccess sees . as a regex command, not as an actual ., you need to backslash it?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文