.htaccess 中的重定向 301 导致 500 服务器错误(重定向到非 URL)

发布于 2024-10-22 02:31:25 字数 597 浏览 1 评论 0原文

有这样的错误。

Redirect 301 规则添加到 .htaccess 文件时,例如:

Redirect 301 "/page1.html" "/dir1/"

我的网站因 500 服务器错误而失败,并且在 apache 错误日志中出现此错误:

[Wed Mar 16 11:08:52 2011] [alert] [client 127.0.0.1] /home/htdocs/site.com/www/.htaccess: Redirect to non-URL

Mod rewrite 也已安装尝试提供不带引号的网址。

在生产服务器上,这个 .htaccess 工作正常,但在本地会导致麻烦

请有任何想法)


此规则有效,

Redirect 301 "/page1.html" "http://www.site.com/dir1/"

但我需要一种提供相对路径的方法完整网址(生产服务器以这种方式工作)

have such kind of error.

When adding Redirect 301 rule to .htaccess file like:

Redirect 301 "/page1.html" "/dir1/"

My site fails with 500 server error and in apache error log this error appears:

[Wed Mar 16 11:08:52 2011] [alert] [client 127.0.0.1] /home/htdocs/site.com/www/.htaccess: Redirect to non-URL

Mod rewrite is installed, also tried to provide urls without quotes.

On production server this .htaccess works fine, but on local causes troubles

Any ideas, please)


This rule works

Redirect 301 "/page1.html" "http://www.site.com/dir1/"

but I need a way to supply relative paths instead of full urls (production server works that way)

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

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

发布评论

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

评论(4

亣腦蒛氧 2024-10-29 02:31:25

将所有 Redirect 301 规则更改为:

RewriteRule ^/page1.html$ /dir1/page.html [R=301,L]

现在有效。但它在生产中是如何运作的呢?

Changed all Redirect 301 rules to:

RewriteRule ^/page1.html$ /dir1/page.html [R=301,L]

now working. But how does it work on production?

雨落□心尘 2024-10-29 02:31:25

对于我来说,我遇到了完全相同的问题。在“/mypage”前面添加“http://domain.com”有效;我仍在测试让它在没有的情况下工作,就像在我的生产服务器上一样。所以我的本地测试环境中的 .htaccess 是这样的:

损坏:
重定向 301 /mypage /directory1/sub-directory/mypage/

已修复:
重定向 301 http://mydomain.com/mypage http://mydomain.com/directory1/sub-directory/我的页面/

For me, I had the exact same issue. Adding "http://domain.com" in front of "/mypage" worked; I am still testing to get it to work without, as is does on my production server. So my .htaccess on my local testing environment, went like this:

BROKEN:
Redirect 301 /mypage /directory1/sub-directory/mypage/

FIXED:
Redirect 301 http://mydomain.com/mypage http://mydomain.com/directory1/sub-directory/mypage/

冰火雁神 2024-10-29 02:31:25

我遇到了同样的问题,对我来说这也不起作用:

RewriteRule ^/page1.html$ /dir1/page.html [R=301,L]

对我有用的是删除前导斜杠,并使用 ? 添加软尾斜杠,如下所示:

RewriteRule ^(page1.html)/?$ dir1/page.html [R=301,L]

I had same issue, for me this didn't work as well:

RewriteRule ^/page1.html$ /dir1/page.html [R=301,L]

What worked for me is to remove the leading slash, and add soft tailing slash with ?, like this:

RewriteRule ^(page1.html)/?$ dir1/page.html [R=301,L]
抱着落日 2024-10-29 02:31:25

请尝试一下,它按预期工作。

 <IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  Redirect 301 /our_clients/nike /project/nike-nofyme-campaigns
 </IfModule>

Please try this, it's working as expected.

 <IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  Redirect 301 /our_clients/nike /project/nike-nofyme-campaigns
 </IfModule>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文