.htaccess (mod_rewrite) 出现问题。 RewriteRule 无法正常工作

发布于 2024-09-02 16:22:36 字数 689 浏览 0 评论 0原文

我的两个重写规则有问题。

.htaccess:

# protect the htaccess file
<files .htaccess>
 order allow,deny
 deny from all
</files>

RewriteEngine On
Options +FollowSymlinks
Options -Indexes
RewriteBase /test/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^download/([0-9]+)$ download.php?id=$1 [L]
RewriteRule ^(.*)$ index.php?c=view&misc=$1 [B]

如果 url 包含 download(有些像这样:mydomain.com/download/9),则第一条规则应将此请求重定向为 download.php?id=9。但事实并非如此。

var_dump($_GET) 显示以下内容:

array(2) { ["c"]=>  string(4) "view" ["misc"]=>  string(9) "index.php" } index.php

有什么想法吗?

I have a problem with my two RewriteRules.

.htaccess:

# protect the htaccess file
<files .htaccess>
 order allow,deny
 deny from all
</files>

RewriteEngine On
Options +FollowSymlinks
Options -Indexes
RewriteBase /test/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^download/([0-9]+)$ download.php?id=$1 [L]
RewriteRule ^(.*)$ index.php?c=view&misc=$1 [B]

If the url contains download (some like this: mydomain.com/download/9) the first rule should redict this request to download.php?id=9. But it doesn't.

var_dump($_GET) shows the following:

array(2) { ["c"]=>  string(4) "view" ["misc"]=>  string(9) "index.php" } index.php

Any ideas?

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

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

发布评论

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

评论(2

好的,我解决了问题。

# protect the htaccess file
<files .htaccess>
 order allow,deny
 deny from all
</files>

RewriteEngine On
Options +FollowSymlinks
Options -Indexes

RewriteBase /test/download/
RewriteRule ^download/([0-9]+)$ download.php?id=$1 [L]

RewriteBase /test/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?c=view&misc=$1 [B]

谢谢你们! :)

Ok, I solved the problem.

# protect the htaccess file
<files .htaccess>
 order allow,deny
 deny from all
</files>

RewriteEngine On
Options +FollowSymlinks
Options -Indexes

RewriteBase /test/download/
RewriteRule ^download/([0-9]+)$ download.php?id=$1 [L]

RewriteBase /test/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?c=view&misc=$1 [B]

Thanks guys! :)

雨落□心尘 2024-09-09 16:22:36

问题不在于规则。它在这里工作。

http://wingsoflol.org/download/9

我的 download.php 包含

Hi!
<br>Id = <?
echo $_GET['id'];
?>

,规则是


RewriteRule ^download/([0-9]+)$ download.php?id=$1 [L]

您确定 RewriteBase 应该是 /test/ 吗?

The problem is not with the rule. It works here.

http://wingsoflol.org/download/9

My download.php contains

Hi!
<br>Id = <?
echo $_GET['id'];
?>

and the rule is


RewriteRule ^download/([0-9]+)$ download.php?id=$1 [L]

Are you sure the RewriteBase should be /test/ ?

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