Not able to avoid external redirect

In my .htaccess file, I have this code:


# -FrontPage-

IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*

<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>

AuthName xyz.com
AuthUserFile /home/localtig/public_html/_vti_pvt/service.pwd
AuthGroupFile /home/localtig/public_html/_vti_pvt/service.grp

Options +FollowSymLinks
RewriteEngine on
RewriteCond $1 !(^index\\.php|\\.(gif|jpe?g|ico|css)|^robots\\.txt)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_URL} !=/favicon.ico
RewriteRule ^(.*)$ http://xyz.com/index.php?q=$1 [L,QSA]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\\ /([^/]+/)*index\\.php\\ HTTP/
RewriteRule ^(([^/]+/)*)index\\.php$ http://www.xyz.com/$1 [R=301,L]

This should redirect a url like http://subdomain.xyz.com/sample-page to http://www.xyz.com/index.php?q=sample-page

…while retaining the URL in the address bar as http://subdomain.xyz.com/sample-page

The problem is that this same .htaccess file acts differently on 2 machines.

One of them has version 2.2.13 of apache, and another has 1.3.37. On the former, the redirect is becoming external (i. e. the URL in the address bar is changing), while in the latter (1.3.37), it works just fine.

I do not even know if (or think) the version is a problem, since the 2.2.13 version, for another site hosted on it using the same httpd.conf file and with exactly the same directives, works just fine for all rewrites.

Does anyone have a clue what is going wrong? I’ll be grateful for any help!

KKK,

RewriteEngine on
RewriteCond [COLOR="Red"]$1[/COLOR] !(^index\\.php|\\.(gif|jpe?g|ico|css)|^robots\\.txt)$
[COLOR="Red"]# $1 does NOT exist so this will ALWAYS be false - no match = no redirect![/COLOR]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_URL} !=/favicon.ico
RewriteRule ^(.*)$ http://xyz.com/index.php?q=$1 [L,QSA]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\\ /([^/]+/)*index\\.php\\ HTTP/
RewriteRule ^(([^/]+/)*)index\\.php$ http://www.xyz.com/$1 [R=301,L]
# 1. WHY would anyone use {THE_REQUEST}?
# 2. If you feel you have to use {THE_REQUEST},
#  why match all the garbage at the ends of the string?
# 3. If you merely want to strip the DirectoryIndex, link that way
#  rather than add this "@#$%" to your .htaccess
# 4. Apache MAY be configured to display the redirect you are
#  forcing it to make to $1's DirectoryIndex making this code
#  USELESS (LOOPY).
# 5. Of course, that's merely "IMHO."

Oh, Apache 1.x and Apache 2.x? The 1.x version will REQUIRE that you specifically include a / after the start anchor (the second RewriteRule will FAIL because of this) while the 2.x flavor will fail if it’s included. To write code for both flavors, use ^/? as that is acceptable to both.

Regards,

DK