Forum Moderators: phranque

Message Too Old, No Replies

Really frustrated with this htaccess file

         

cool_jack

3:36 pm on Feb 26, 2009 (gmt 0)

10+ Year Member



My boss has given me this htaccess file along with the site and I am really frustrated as I can't able to solve this.

Here it goes:


<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]

# Redirect to add "www" prefix for existing or new domain
RewriteCond %{HTTP_HOST} ^mywebsite\.com [NC,OR]
RewriteCond %{HTTP_HOST} ^secondsite\.com [NC]
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L]

# Internally rewrite new domain home page requests to a specific page
RewriteCond %{HTTP_HOST} ^www\.othersite\.com
RewriteRule ^$ /somefile.shtml [L]
</IfModule>
ErrorDocument 404 http://www.mywebsite.com/

Now I am getting the following errors

1. My wordpress blog is giving following error

Redirect Loop

Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

The browser has stopped trying to retrieve the requested item. The site is redirecting the request in a way that will never complete.

* Have you disabled or blocked cookies required by this site?
* NOTE: If accepting the site's cookies does not resolve the problem, it is likely a server configuration issue and not your computer.

2. The errodocument is behaving in strange way i.e it is not redirecting to mywebsite.com but instead it redirects to mywebsite.com/blog with loop error.

Please solve this..I would be grateful to you guys...

jdMorgan

5:13 pm on Feb 26, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



These rules are in the wrong order, and have apparently been incorrectly modified.

Also, you cannot use a full URL in an ErrorDocument directive; If you do, then as documented, the server will respond with a 302-Found response, instead of a 404-Not Found. This can very seriously damage your search engine rankings.

I'd suggest:


ErrorDocument 404 /404-error.html
#
RewriteEngine on
#
# Externally redirect to add "www" prefix for existing or new domain
# and correct FQDN hostnames or hostnames with appended port number
RewriteCond %{HTTP_HOST} ^(mywebsite\.com) [NC,OR]
RewriteCond %{HTTP_HOST} ^(secondsite\.com) [NC,OR]
RewriteCond %{HTTP_HOST} ^www\.([^.]+\.com)\. [NC,OR]
RewriteCond %{HTTP_HOST} ^www\.([^.]+\.com):[0-9]+ [NC]
RewriteRule (.*) http://www.%1/$1 [R=301,L]
#
# Internally rewrite new domain home page requests to a specific page
RewriteCond %{HTTP_HOST} ^www\.othersite\.com
RewriteRule ^$ /somefile.shtml [L]
#
# If the requested URL does not resolve to an existing file or directory and we
# haven't already done so, rewrite the request to the /blog/index.php script
RewriteCond %{REQUEST_URI} !^/blog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]

Also, best-practice for usability indicates that 404 errors should not be redirected to the home page, because this confuses visitors and search engines; Instead, serve a custom 404 error page that clearly (and somewhat apologetically) explains/acknowledges the problem, and then offers resources to help the visitors find what they were looking for. This can be as simple as a text link and ten-second meta-refresh to the home page, or a home-page link, a link to a relevant category page derived from the requested URL, and a link to a site search facility or a search box on the error page itself.

Jim

cool_jack

4:18 am on Feb 27, 2009 (gmt 0)

10+ Year Member



Thanks for your quick reply but unfortunately the loop problem is still there.

wheelie34

10:38 am on Feb 27, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Did you flush the browser cache?

cool_jack

12:51 pm on Feb 27, 2009 (gmt 0)

10+ Year Member



yes..I cleared all the browser data but still i am stuck in this loop which is a wordpress blog.

Caterham

1:11 pm on Feb 27, 2009 (gmt 0)

10+ Year Member



My wordpress blog is giving following error

May be replace giving with causes. I wouldn't wonder if WP is configured to use test.com and redirects www.test.com to test.com while your RewriteRule does the opposite and you're playing ping pong.

jdMorgan

4:22 pm on Feb 27, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Comment out all the rules, then un-comment them one by one, and tell us which one(s) cause the problem.

Jim