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

时间:2022-10-06 07:44:13

have such kind of error.

有这样的错误。

When adding Redirect 301 rule to .htaccess file like:

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

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

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

我的站点因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 is installed, also tried to provide urls without quotes.

安装了Mod重写,也试图提供没有引号的网址。

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

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

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)

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

3 个解决方案

#1


8  

Changed all Redirect 301 rules to:

将所有重定向301规则更改为:

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

now working. But how does it work on production?

工作中。但它如何在生产中发挥作用?

#2


1  

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:

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

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

BROKEN:重定向301 / mypage / directory1 /子目录/ mypage /

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

修复:重定向301 http://mydomain.com/mypage http://mydomain.com/directory1/sub-directory/mypage/

#3


1  

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]

#1


8  

Changed all Redirect 301 rules to:

将所有重定向301规则更改为:

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

now working. But how does it work on production?

工作中。但它如何在生产中发挥作用?

#2


1  

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:

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

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

BROKEN:重定向301 / mypage / directory1 /子目录/ mypage /

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

修复:重定向301 http://mydomain.com/mypage http://mydomain.com/directory1/sub-directory/mypage/

#3


1  

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]