htaccess Redirect Loop only on Home Page - apache

All of a sudden this morning I'm having a problem with accessing the home page to my site.
I didn't make any changes so I'm not sure what the issue is. I'm guessing it has something to do with my .htaccess file.
All other pages to my site, I can access without a problem.
Below is my htaccess file. Any help would be appreciated. Thanks in advance.
Options -Indexes
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^hats-n-caps/(.*)$ http://www.domain-domain.com/apparel/hats-n-caps/$1 [R=301,L]
RewriteRule ^electronics/laser-pointers/(.*)$ http://www.domain-domain.com/desktop-office/laser-pointers/$1 [R=301,L]
#RewriteCond %{HTTP_HOST} !^www.domain-domain.com$ [NC]
#RewriteRule ^(.*)$ http://www.domain-domain.com/$1 [L,R=301]
RewriteCond %{REQUEST_URI} (^(.*)/site-map)
RewriteRule ^site-map$ /inc/pages/site-map.php [L]
RewriteCond %{REQUEST_URI} (^(.*)/site-map/products-([0-9]+))
RewriteRule ^site-map/products-([0-9]+)$ /inc/pages/site-map.php?type=product&page=$1 [L]
RewriteCond %{REQUEST_URI} (^(.*)/site-map/catalogs-([0-9]+))
RewriteRule ^site-map/catalogs-([0-9]+)$ /inc/pages/site-map.php?type=catalog&page=$1 [L]
RewriteCond %{REQUEST_URI} (^(.*)/site-map/pages-([0-9]+))
RewriteRule ^site-map/pages-([0-9]+)$ /inc/pages/site-map.php?type=pages&page=$1 [L]
RewriteCond %{REQUEST_URI} (^(.*)-p-(.*).html*)
RewriteRule ^(.*)-p-(.*).html$ product_info.php?products_id=$2&%{QUERY_STRING}[L]
RewriteCond %{REQUEST_URI} (^(.*)-c-(.*).html*)
RewriteRule ^(.*)-c-(.*).html$ product_info.php?catalog_id=$2&%{QUERY_STRING}[L]
RewriteCond %{REQUEST_URI} !(^(.*)-c-(.*).html*|^(.*)-p-(.*).html*|^/index.php|^/sitemap.xml.*|^/info.php.*|^/google_base_feed.xml.*|^/BingSiteAuth.xml.*|^/test.html.*|^/test.*|^/ajaxplorer.*|/livechat.*|^/phpmyadmin.*|^/ControlPanel.*|^/actikare.*|^/amwater.*|^/phi.*|^/sas.*|^/blog.*|^/cfscg.*|^/chase.*|^/cleaver.*|^/clubz.*|^/medicone.*|^/net2ftp.*|^/college-net.*|^/ducks.*|^/fast-teks.*|^/gatesgroup.*|^/guesthouse.*|^/neighborcare.*|^/pdf.*|^/reedrill.*|^/survey.*|^/temp.*|^/templates.*|^/tidewater.*|^/tuthill.*|^/uploads.*|^/upload.*|^/_include.*|^/product_info.*|^/server_request.*|^/server_request_products.*|^/admin.*|^/img/.*|^/images/.*|^/spaw2?|^/static/.*|^/tmp/|^/_include/|^/robots.txt|^/LiveSearchSiteAuth.xml|^/favicon.ico|/SiteReturn/.*|^/inc/pages/site-map.php(.*)|^/carousel_products.php)
RewriteRule (.*)$ /index.php [L]
RewriteCond %{HTTP_HOST} ^domain-domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.domain-domain.com$
RewriteRule ^/?$ "\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^domaindomain\.co$ [OR]
RewriteCond %{HTTP_HOST} ^www\.domaindomain\.co$
RewriteRule ^/?$ "\/" [R=301,L]

This line:
RewriteRule ^/?$ "\/" [R=301,L]
Is what's causing your redirect loop. Get rid of the entire rule:
# RewriteCond %{HTTP_HOST} ^domaindomain\.co$ [OR]
# RewriteCond %{HTTP_HOST} ^www\.domaindomain\.co$
# RewriteRule ^/?$ "\/" [R=301,L]
It essentially redirects requests to the root / to itself.

Related

How To exclude a Folder from 301 Redirect .htaccess

I have a 301 redirect on the domain goodereader.com that points to goodereader.com/blog/
I wanted to setup a forum, and wanted to exclude /forum/ from being 301'd
Here my current .htaccess
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/forum/.*$
RewriteCond %{HTTP_HOST} ^www\.goodereader\.com$ [NC]
RewriteRule ^(.*)$ http://goodereader.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^goodereader\.com$
RewriteRule (.*) http://goodereader.com/blog/$1 [R=301,L]
RewriteRule ^$ blog [L]
<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
</IfModule>
From the comments, you can fix this by adding the same condition to the 2nd rule. Rewrite conditions only get applied to the immediately following rule, they're not global in any way.
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/forum/.*$
RewriteCond %{HTTP_HOST} ^www\.goodereader\.com$ [NC]
RewriteRule ^(.*)$ http://goodereader.com/$1 [L,R=301]
RewriteCond %{REQUEST_URI} !^/forum/.*$
RewriteCond %{HTTP_HOST} ^goodereader\.com$
RewriteRule (.*) http://goodereader.com/blog/$1 [R=301,L]
RewriteRule ^$ blog [L]
or use a pass through:
RewriteEngine On
RewriteRule ^forum/ - [L]
RewriteCond %{HTTP_HOST} ^www\.goodereader\.com$ [NC]
RewriteRule ^(.*)$ http://goodereader.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^goodereader\.com$
RewriteRule (.*) http://goodereader.com/blog/$1 [R=301,L]
RewriteRule ^$ blog [L]
Make sure to clear your browser's cache. 301 redirects are permanent and the browser will always cache them.

Redirect HTTPS to HTTP and NON WWW to WWW

I have a problem with my redirects and im guessing its because i keep copy and pasting my htaccess rules.
I need to redirect all https traffic to http, and all non www to www. I also have some more rules to make pretty links
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI}
RewriteRule (.*\.php)\.$ /$1 [R=301,L]
RewriteRule ^people/([^/]*)/([^/]*)/([^/]*)$ /profile.php?county=$1&name=$2&id=$3 [L]
RewriteRule ^people-in-(.*) /people.php?county=$1 [L]
RewriteCond %{HTTP_HOST} ^ties\.co.uk$
RewriteRule (.*) http://www.ties.co.uk/$1 [R=301,L]
RewriteCond %{REQUEST_URI} ^/index.php$
RewriteRule (.*) / [R=301,L]
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
ErrorDocument 404 /notfound.php
You can combine:
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI}
and
RewriteCond %{HTTP_HOST} ^ties\.co.uk$
RewriteRule (.*) http://www.ties.co.uk/$1 [R=301,L]
into a single rule that needs to be right below RewriteEngine On:
RewriteCond %{HTTPS} on [OR]
RewriteCond %{HTTP_HOST} ^ties\.co\.uk$ [NC]
RewriteRUle ^(.*)$ http://www.ties.co.uk/$1 [R=301,L]

Using HTACCESS to rewrite index.html AND redirect http://site.com to http://www.site.com

In .htaccess I see how to rewrite /index.html to point to the main domain:
RewriteEngine on
RewriteCond %{THE_REQUEST} ^.*\/index\.html?\ HTTP/
RewriteRule ^(.*)index\.html?$ "/$1" [R=301,L]
I also understand how .htaccess can prevent the site from being indexed under WWW and without it
RewriteEngine on
rewritecond %{http_host} ^mycustomcloset.com [nc]
rewriterule ^(.*)$ http://www.mycustomcloset.com/$1 [r=301,nc]
But how do you do both at the same time?
In other words, I'd like mycustomcloset.com and mycustomcloset.com/index.html both to point to http://www.mycustomcloset.com.
I did not understand the first code on your question, however you can still try this one:
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^(.*) http://www.%{HTTP_HOST}/$1 [R,NE]
Now, if you also want to redirect mycustomcloset.com/index.html and www.mycustomcloset.com/index.html into www.mycustomcloset.com then you can try this:
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{REQUEST_URI} !^/index.html$
RewriteRule ^(.*) http://www.%{HTTP_HOST}/$1 [R,NE]
RewriteRule ^index.html$ http://www.mycustomcloset.com [R,NE]

Keep referer mod_rewrite

Please help with the following question.
There is domain1.com, domain2.com, domain3.com. With the help of organized htaccess redirects to domain.com. But in the apache logs for domain.com, I do not see the referer, since when domain1 or domain2 request came.
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com?$ [NC]
RewriteRule ^$ http://domain.com/$1 [R=302,L]
RewriteCond %{HTTP_HOST} !^domain\.com$ [NC]
RewriteCond %{HTTP_HOST} !^rss\.domain1\.com$ [NC]
RewriteCond %{HTTP_HOST} !^contacts\.domain2\.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [R=302,L]
RewriteCond %{HTTP_HOST} ^rss.domain1.com$
RewriteRule ^/?$ "http\:\/\/www\.google\.com" [R=302,L]
RewriteCond %{HTTP_HOST} ^contacts.domain2.com$
RewriteRule ^/?$ "https\:\/\/www\.google\.com" [R=301,L]
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(.*)$ / [R=302,L]

redirect all non www to www. for Cakephp site

Hi allm i'm having some issues in redirecting the non www pages to the www. pages for my cakephp site.
I've tried
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]
but it doesn't seem to work.
My cakephp app resides in a subfolder. eg. www.domain.com/my.
i've added the above code to the root folder, www.domain.com/
any suggestions? thanks?
*update
This my .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^.*$ http://www.domain.com%{REQUEST_URI} [R=301,L]
i'm getting an extra webroot/index.php?url= inserted into the url. Instead of www.domain.com/my/apple, i'm getting www.domain.com/my/webroot/index.php?url=apple
thanks to all once again.
Your code is not quite right. See below.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^.*$ http://www.domain.com%{REQUEST_URI} [R=301,L] # <-- Mind the 'L'!
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
if domain is .co.uk
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.co\.uk$ [NC]
RewriteRule ^.*$ http://www.domain.co.uk%{REQUEST_URI} [R=301,L]
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app/webroot/$1 [QSA,L]
I have tried the below code below and it worked for me:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^gigsadda\.com$ [NC]
RewriteRule ^.*$ http://www.gigsadda.com%{REQUEST_URI} [R=301,L]
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>