Forum Moderators: phranque

Message Too Old, No Replies

.htaccess giving me server error HELP

.htaccess

         

Diamonelle

6:37 pm on Jan 21, 2009 (gmt 0)

10+ Year Member



The following code is giving me a server side error message, then no one can access the site, then when I go to remove it, it has disapreared from the server so I can't remove it. I can't see anything wrong, it was working before, then I added new redirects and it stopped working. Can anyone help me? I saved it as an ANSI file called .htaccess each redirect is on a unique line with a line space between each redirect.

redirect 301 /_english/index.html http://www.example.com/index_e.php

<snip>

redirect 301 /_francais/liens/index.html http://www.example.com/index_f.php?s1=li

redirect 301 /_francais/map_f.htm http://www.example.com/index_f.php?s1=map-index

Thank you

[edited by: jdMorgan at 7:48 pm (utc) on Jan. 21, 2009]
[edit reason] Examplified, trimmed. Please see Terms of Service. [/edit]

jdMorgan

7:14 pm on Jan 21, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That was a bit too much code for the members here to review.

The most likely cause is either a syntax error or a new redirect that matches the output of an existing redirect, and which redirects to a URL that matches that first redirect -- Setting up an 'infinite' redirection loop. Your server error log may be most useful to you (and to the members here) in providing the information needed to find this, if it isn't obvious.

Also, please do not use your real domain name -- both to comply with our terms of service and to protect your own site.

Thanks,
Jim

jdMorgan

7:34 pm on Jan 21, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I suspect these two lines:
redirect 301 /_english/fil/fil_5/fil_5a_e.htm#codexrep http://www.example.com/index_e.php?s1=idf-fil&s2=codex&page=rep-rap

redirect 301 /_francais/fil/fil_5/fil_5a_f.htm#codexrep http://www.example.com/index_f.php?s1=idf-fil&s2=codex&page=rep-rap

Be aware that most browsers do not send 'fragments' or 'named anchors' such as "#codexrep" to the server, so this will not work as expected for any browser I know of except for Apple's Safari browser and derivatives.

There is potentially a much larger problem here, in that you are redirecting from 'SEO friendly' URLs to dynamic (and therefore 'unfriendly') URLs, and telling the search engines to replace the friendly URLs with the unfriendly ones. This can cause trouble in two ways: First, search engines, although they are getting better, handle static-looking SEO friendly URLs better than they do dynamic URLs. And secondly, if you link to SEO-friendly URLS and then redirect every request for such URLs, you will leave the search engines in a permanent state of confusion, and they will therefore lower their 'quality rating' of your site. In addition, every client that requests one of the friendly URLs will suffer the delay of waiting for the server to respond with a 301 redirect, and then have to re-request the desired resource using the dynamic URL provided in that 301 response. So, the client must send two requests and wait for two replies from your server for every page requested. This of course will also make a mess of your log files, and skew your site statistics, showing two page loads for every page actually delivered.

The bottom line is that I believe you would be far better off using internal rewrite (mod_rewrite) instead of external redirects. You may also benefit greatly from using the power of regular-expressions pattern-matching to reduce the number of rules by half (or more).

For example, using the above two URLs after removing the 'fragment identifiers' we can use mod_rewrite to do an internal rewrite like this:


RewriteRule ^_(english¦francais)/fil/fil_5/fil_5a_([ef])\.htm /index_$2.php?s1=idf-fil&s2=codex&page=rep-rap [L]

to replace two rules with one, and handle both the french and english URLs with one rule.

Here, the "$2" in the substitution URL on the right back-references either an "e" or an "f", as captured using the "([ef])" subpattern in the second parenthesized regular-expressions sub-pattern on the left. (You will need to replace the broken pipe "¦" character in the first sub-pattern with a solid pipe before use; Posting on this forum modifies the pipe character.)

You may also be able to take advantage of other 'regularities' in the URLs you are rewriting, to use one rule for several (or many) URLs.

As mentioned, this code does not do a URL-to-URL external redirect; It simply maps requests for the friendly URLs to the internal filepaths needed to generate the proper page content.

[edit] Amended per the following post to prevent propagation of bad code. :o [/edit]

Jim

[edited by: jdMorgan at 8:16 pm (utc) on Jan. 21, 2009]

g1smd

8:09 pm on Jan 21, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



This might be better:

RewriteRule ^_(english¦francais)/fil/fil_5/fil_5a_([ef])\.htm /index_$2.php?s1=idf-fil&s2=codex&page=rep-rap [L]