How can I fix too many redirects caused by .htaccess?

I recently added a Wordpress blog to a client website. I create a subdirectory and install Wordpress there. Everything worked fine until I added the .htaccess file to the root directory.

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

Now when I click on the blog link, I get the following error

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.

Does anyone know how to solve this problem? I am not at all familiar with .htaccess.

Edit: Just to be clear, 301 redirect works just fine for all pages except the blog folder. If you type websitename.com, you will go to www.websitename.com. However, if you type websitename.com/blog, you will encounter this error. The blog in this example points to a Wordpress folder.

+5
source share
5 answers

*.suncoastlaw.com/xx -> www.suncoastlaw.com/xx ?

conf

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

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

rewritecond %{http_host} !www.suncoastlaw.com

www.suncoastlaw.com,

conf

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
+4

, "www."?

:

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

, , : www

+3

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- , - IP-. ;)

+1

. , , , -, . , -, , WWW. URL- . WWW.

0

I had the same problem. The problem is not the rule. The rule was correct, but the order of the rules in .htaccess was not. This is what I had before. Note. I rewrite non-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]

I changed to

 #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]
0
source

All Articles