Forum Moderators: phranque

Message Too Old, No Replies

Apache1 to Apache2 rewrite problem

         

hitura

12:15 pm on Dec 25, 2008 (gmt 0)

10+ Year Member



Hi,

I have moved some clients from a server with apache1 to a server with apache 2 and now their websites are not showing due to .htaccess errors.

The .htaccess contents are as follows:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index.php\ HTTP/
RewriteRule ^index.php$ [%{HTTP_HOST}...] [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /sitemap.php\?num=([^&]+)&page=([^\]+)\ HTTP/
RewriteRule ^sitemap.php$ [%{HTTP_HOST}...] [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /search.php\?page=([^\]+)\ HTTP/
RewriteRule ^search.php$ [%{HTTP_HOST}...] [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /range.php\?page=([^\]+)\ HTTP/
RewriteRule ^range.php$ [%{HTTP_HOST}...] [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /terms.php\ HTTP/
RewriteRule ^terms.php$ [%{HTTP_HOST}...] [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /privacy.php\ HTTP/
RewriteRule ^privacy.php$ [%{HTTP_HOST}...] [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /antispam.php\ HTTP/
RewriteRule ^antispam.php$ [%{HTTP_HOST}...] [R=301,L]

Can anyone shed some light on what changes are needed to get this working on apache2?

In the apache logs I will get errors like this:
cannot compile regular expression '^[A-Z]{3,9}\\ /sitemap.php\\?num=([^&]+)&page=([^\\]+)\\ HTTP/'

jdMorgan

4:59 pm on Dec 25, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The regex compile problem is caused by this sub-pattern, which is invalid: "([^\]+)"

It is doubtful that this code worked properly on Apache 1.3 either, unless this was introduced by some sort of copy-and-paste error.

The problem is that the apparent intent is to "match one or more characters not a space," but the space character is missing from the group. You need "([^\ ]+)" -- or to illustrate clearly, "([^\<space character here>]+)"

There is a larger problem with the code, however, in that several of the rules appear to be intended to remove query strings from .php URLs and redirect them to .html URLs -- I can't be sure, because your code has no comments in it whatsoever. However, the RewriteConds of those rules will prevent them from ever being invoked when a query string is present, because the RewriteCond patterns do not allow for a query string appended to the URL. To illustrate, this rule


RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index.php\ HTTP/
RewriteRule ^index.php$ http://%{HTTP_HOST}/index.html? [R=301,L]

should probably be

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.ph[b]p(\?[^\ ]*)?\ H[/b]TTP/
RewriteRule ^index\.php$ http://%{HTTP_HOST}/index.html? [R=301,L]

in order to allow query strings to be removed by the subsequent rule -- including blank query strings.

Note also that the literal periods in the RewriteCond and RewriteRule patterns have been escaped.

This needs to be fixed in four of the rules -- The ones for index.php, terms.php, privacy.php, and antispam.php.

Jim

[edited by: jdMorgan at 5:02 pm (utc) on Dec. 25, 2008]