.htaccess 不重写 url

发布于 2024-12-12 19:58:20 字数 671 浏览 0 评论 0原文

我有这个问题: 服务器的管理员说他为 apache 服务器启用了 rewrite_module,但是当我将一些测试文件上传到服务器来测试此功能时,它不起作用。

我在本地主机上启用了它,并且它在那里工作得很好。

.htaccess 内容:

Options +FollowSymlinks
RewriteEngine on 
RewriteRule ^games/(.*)$ games.php?id=$1 [L]

games.php 内容:

<?php 
$var = $_GET['id'];
echo $var;
?>

URLS:

localhost url:http://localhost/testing/games/123123
production url:http://mysite.com/test2/games/123123 

test2 是包含文件(.htaccess 和 games.php)的文件夹 在生产中发生的情况是,当我输入此内容时,我得到页面 games.php 但 id 没有得到回显,并且查询字符串为空,而不是得到我提供的 id 123123。对于 localhost,一切正常,我得到 id 回显。 也许管理员是错的还是什么?先感谢您。

I have this problem:
The administrator of the server says that he had rewrite_module enabled for the apache server but when I upload some test files to the server to test this functionality it does not work.

I have it enabled at localhost and it works perfectly fine there.

.htaccess content:

Options +FollowSymlinks
RewriteEngine on 
RewriteRule ^games/(.*)$ games.php?id=$1 [L]

games.php content:

<?php 
$var = $_GET['id'];
echo $var;
?>

URLS:

localhost url:http://localhost/testing/games/123123
production url:http://mysite.com/test2/games/123123 

test2 is the folder that contains the files (.htaccess and games.php)
What happens in production is that when i type this i get the page games.php but the id does not get echoed and query string is empty instead of getting the id 123123 which I provided.For localhost everything works fine and I get the id echoed.
Maybe the administrator is wrong or what? Thank you in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

凉城已无爱 2024-12-19 19:58:20

您位于子目录中,并且告诉引擎在请求完全以“games”开头时进行重写。您可以尝试删除插入符号 ^,或将其替换为斜杠 / ... 或在 RewriteEngine on :

RewriteBase /testing/

in production:

RewriteBase /test2/

之后添加此内容,或者尝试:

RewriteEngine On
RewriteBase /test2/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^games/(.*)$ games.php?id=$1 [QSA,L]

You are in subdirectories and you're telling the engine to rewrite when the request begins exactly with 'games'. You can try to remove the caret ^, or replace it with a slash / ... or add this after RewriteEngine on :

RewriteBase /testing/

in production:

RewriteBase /test2/

Or try:

RewriteEngine On
RewriteBase /test2/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^games/(.*)$ games.php?id=$1 [QSA,L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文