mod_rewrite 失败:.htaccess 或服务器配置问题?

发布于 2024-08-01 19:03:28 字数 1469 浏览 10 评论 0原文

我正在开发的应用程序使用特定的文件目录结构。 通过使用 mod_rewrite 和 .htaccess 文件,我设法为我们的用户提供友好的 URL。 它在我的本地服务器上工作正常,但一旦在生产服务器上,它就会失败:显然,服务器在 .htaccess 有机会启动之前抛出 404 错误。

这是我正在处理的 .htaccess (引用为(1)如下):

IndexIgnore *
#Options +FollowSymLinks
RewriteEngine on

RewriteOptions inherit

RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule ^(.*)$ /~extranet/extranet/$1 [NC,L,QSA]

在服务器上,返回404:

服务器找不到请求的内容 页面:

/~extranet/extranet/dev/foo/ 
  

(端口 80)

事实上,尽管 phpinfo() 在加载的模块中列出了 mod_rewrite,但似乎任何重定向都会失败。

服务器是全新的。 (如果有帮助,404页面列出了 Apache/2.0.63 (Unix) mod_ssl/2.0.63 OpenSSL/0.9.8e-fips-rhel5 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 PHP/5.2.8 Server )

我应该在哪里查找错误/配置错误?

更新:这里的更多信息

是文件/文件夹结构和使用的每个 .htaccess:

<IP-ADDRESS>/~extranet/.htaccess (1)
<IP-ADDRESS>/~extranet/extranet/
                              L .htaccess (2)
                              L/dev/
                                   L .htaccess (3)
                                   L index.php
                              L/stable/
                                   L .htaccess (3)
                                   L index.php

(1) 将所有请求重定向到文件夹“extranet” (2) 将所有不包含“/dev/”的请求重定向到文件夹“stable” (3) 将/extranet/foo/bar/重写为index.php?app=foo&do=bar

The application i'm developing uses a certain file directory structure. Via the use of mod_rewrite and .htaccess files, i manage to have friendly urls for our users. It works fine on my local server, but once on the production server, it fails: apparently, the server throws a 404 error before the .htaccess has a chance to kick in.

Here is the .htaccess i'm working on (referenced as (1) here below):

IndexIgnore *
#Options +FollowSymLinks
RewriteEngine on

RewriteOptions inherit

RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule ^(.*)$ /~extranet/extranet/$1 [NC,L,QSA]

On the server, it returns 404:

The server can not find the requested
page:

<IP-ADDRESS>/~extranet/extranet/dev/foo/

(port 80)

In fact, it seems any redirect fails, although phpinfo() lists mod_rewrite among the loaded modules.

The server is brand new. (In case it helps, the 404 page lists Apache/2.0.63 (Unix) mod_ssl/2.0.63 OpenSSL/0.9.8e-fips-rhel5 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 PHP/5.2.8 Server )

Where should i look for the mistake/misconfiguration?

UPDATE: more information

here is the file/folder structure and each .htaccess used:

<IP-ADDRESS>/~extranet/.htaccess (1)
<IP-ADDRESS>/~extranet/extranet/
                              L .htaccess (2)
                              L/dev/
                                   L .htaccess (3)
                                   L index.php
                              L/stable/
                                   L .htaccess (3)
                                   L index.php

(1) redirects all requests to folder "extranet"
(2) redirects all requests not containing "/dev/" to folder "stable"
(3) rewrites /extranet/foo/bar/ to index.php?app=foo&do=bar

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

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

发布评论

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

评论(1

栀梦 2024-08-08 19:03:28

这里有一个波形符: /~extranet/extranet/dev/foo/

您指定的正则表达式与波形符不匹配。

也许您需要为远程网络服务器正确指定 RewriteBase?

There's a tilde in here: <IP-ADDRESS>/~extranet/extranet/dev/foo/

Your regexes as specified will not match the tilde.

Perhaps you need to specify your RewriteBase properly for your remote webserver?

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