8

我最近在客户的网站上添加了一个 Wordpress 博客。我创建了一个子目录并在那里安装了 Wordpress。在我将 .htaccess 文件添加到根目录之前,一切正常。

RewriteEngine on
rewritecond %{http_host} ^websitename.com [nc]
rewriterule ^(.*)$ http://www.websitename.com/$1 [r=301,nc] 

现在,当我单击博客链接时,出现以下错误

The webpage at http://websitename.com/blog/ has resulted in too many redirects. 
Clearing    your cookies for this site or allowing third-party cookies may fix the problem. If not, it is possibly a server configuration issue and not a problem with 
your computer.

有谁知道如何解决这个问题?我对.htaccess 一点也不熟悉。

编辑:为了清楚起见,301 重定向适用于所有页面,除了博客文件夹。如果您输入 websitename.com,您将重定向到 www.websitename.com。但是,如果您输入 websitename.com/blog,您将遇到错误。此示例中的博客指向 Wordpress 文件夹。

4

6 回答 6

6

我认为您试图强制“www。”?

使用以下内容:

RewriteCond %{HTTP_HOST} ^suncoastlaw\.com
RewriteRule .* http://www.%{SERVER_NAME}%{REQUEST_URI} [R,L]

要获得更多信息,请查看我在这里写的帖子:强制 www

于 2013-01-26T03:48:55.953 回答
4

你想要*.suncoastlaw.com/xx -> www.suncoastlaw.com/xx吗?

然后你的conf

^(.*)$ http://www.suncoastlaw.com/$1

让 www.suncoastlaw.com/$1 301-> www.suncoastlaw.com/$1

所以会有太多的重定向

改成

rewritecond %{http_host} !www.suncoastlaw.com

当不是 www.suncoastlaw.com 然后重定向

所有重写配置细节都可以在

http://httpd.apache.org/docs/current/mod/mod_rewrite.html

如何追踪

您的http://suncoastlaw.com/blog/重定向到http://www.suncoastlaw.com/blog/然后 http://www.suncoastlaw.com/blog/重定向到http://suncoastlaw.com/blog / 这就是问题

$ curl -I http://suncoastlaw.com/blog/
HTTP/1.1 302 Found
Date: Sat, 26 Jan 2013 13:37:10 GMT
Server: Apache
Location: http://www.suncoastlaw.com/blog/
Content-Type: text/html; charset=iso-8859-1



$ curl -I http://www.suncoastlaw.com/blog/
HTTP/1.1 301 Moved Permanently
Date: Sat, 26 Jan 2013 13:37:21 GMT
Server: Apache
X-Pingback: http://suncoastlaw.com/blog/xmlrpc.php
Location: http://suncoastlaw.com/blog/
Content-Type: text/html; charset=UTF-8
于 2013-01-26T03:51:31.890 回答
1

问题解决了。不幸的是,我无法弄清楚,但我找到了可以的人。显然,问题是由于在我的数据库中,该站点没有 WWW。所以我的博客重定向到我的旧网站的 URL。该问题已通过添加 WWW 得到解决。

于 2013-01-26T20:18:37.463 回答
1

尝试将这些行添加到您的 httpd.conf 文件中,而不是使用 .htaccess 文件来强制 WWW 子域:

RewriteEngine On 
RewriteCond %{HTTP_HOST} !^(127\.0\.0\.0|localhost) [NC]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}$1 [L,R=301]

如果您将仅通过 IP 访问您的 Web 服务器,您可能还想在第二行的列表中添加您的 IP。如需更多解释,还请阅读此线程中的答案;)

于 2013-01-26T03:54:14.767 回答
0

RewriteEngine on rewritecond %{http_host} ^websitename.com [nc] rewriterule ^(.*)$ http://www.websitename.com/ $1 [r=301,nc]

代替

RewriteEngine On RewriteCond %{HTTPS} on RewriteRule (.*) https://% {HTTP_HOST}%{REQUEST_URI}

于 2020-06-18T14:15:15.160 回答
0

我有同样的问题。问题不在于规则。规则是正确的,但 .htaccess 中规则的顺序不正确。这是我以前的。注意我正在重写非www。

  #https
  RewriteCond %{HTTPS} off
  RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

  #remove home
  RewriteCond %{THE_REQUEST} ^.*/home
  RewriteRule ^(.*)home$ https://example.com/$1 [R=301,L] 


 # !IMPORTANT! Set your RewriteBase here and don't forget trailing and leading
 #  slashes.
 # If your page resides at
 #  http://www.example.com/mypage/test1
 # then use
 # RewriteBase /mypage/test1/
 #RewriteBase /
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^(.*)$ index.php?/$1 [L]

 #301 redirect
 RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
 RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]

我改为

 #301 redirect
 RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
 RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]

 #https
  RewriteCond %{HTTPS} off
  RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

  #remove home
  RewriteCond %{THE_REQUEST} ^.*/home
  RewriteRule ^(.*)home$ https://example.com/$1 [R=301,L] 


 # !IMPORTANT! Set your RewriteBase here and don't forget trailing and leading
 #  slashes.
 # If your page resides at
 #  http://www.example.com/mypage/test1
 # then use
 # RewriteBase /mypage/test1/
 #RewriteBase /
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^(.*)$ index.php?/$1 [L]
于 2017-02-19T08:29:00.867 回答