Welcome to WebmasterWorld Guest from 54.167.250.64

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Strange strange rewrite glitch

Adds full server path into URL

     
10:58 pm on Aug 9, 2006 (gmt 0)

Full Member

10+ Year Member

joined:Aug 22, 2003
posts:333
votes: 0


I have a couple of mod_rewrite rules to redirect a domain and the www. variant of a subdomain to the proper subdomain. So [subdomain.domain.com...] redirects to [subdomain.domain.com...]

This works fine in practice except for one directory. For some reason it does something strange when it redirects:

[subdomain.domain.com...]
Redirects to [subdomain.domain.com...]

[subdomain.domain.com...]
Redirects to [subdomain.domain.com...]

It's only happening with this one subdirectory, not with any of the other subdirectories under subdirectory1.

I removed all of the .htaccess files from the directory structure leading up to that directory (including the one from my main domain) and only having one .htaccess for the subdomain which has the following rules in it:

RewriteEngine on
RewriteCond %{HTTP_HOST} otherdomain.org [NC]
RewriteRule (.*) [subdomain.domain.com...] [R=permanent,L]
RewriteCond %{HTTP_HOST} ^www.subdomain.domain.com [NC]
RewriteRule (.*) [subdomain.domain.com...] [R=permanent,L]

And the effect still occurs on subdirectory2. At this stage I'm stumped. I can't see anything in the rewrite rules which would behave differently for a particular subdirectory. My only theory is that the directory name is triggering some strange effect in Apache.

8:20 pm on Aug 10, 2006 (gmt 0)

Full Member

10+ Year Member

joined:Dec 20, 2004
posts:330
votes: 0


Are you using the 2.2 branch? Because there is a bug in previus branches (conflict mod_dir/mod_rewrite), which is fixed since 2.1.
9:39 pm on Aug 10, 2006 (gmt 0)

Full Member

10+ Year Member

joined:Aug 22, 2003
posts:333
votes: 0


Nope, I'm running 1.3.36. Is the problem in versions prior to version 2?
10:07 pm on Aug 10, 2006 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


Do you have access to the httpd.conf configuration file?

Jim

12:47 am on Aug 11, 2006 (gmt 0)

Full Member

10+ Year Member

joined:Aug 22, 2003
posts:333
votes: 0


No, I don't unfortunately.
6:36 pm on Aug 11, 2006 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


Related thread: [webmasterworld.com...]

Look at the DirectoryIndex directive (if any) in .htaccess in the afflicted subdirectory, and be sure that the index filepath is a local URL-path, not including the DocumentRoot path.

A work around might be to add a rule to force a trailing slash on directory requests.

The double-slash in the incorrectly-rewritten URL smacks of a server misconfiguration.

Jim

11:51 pm on Aug 12, 2006 (gmt 0)

Full Member

10+ Year Member

joined:Aug 22, 2003
posts:333
votes: 0


The problem turned out to be because in the subdirectory, I was using "RewriteOptions inherit" so that it would execute the rules in my main .htaccess file. Once I took that out, it worked fine.

I believe the reason is because when it came to evaluate:

RewriteCond %{HTTP_HOST} ^www.subdomain.domain.com [NC]
RewriteRule (.*) [subdomain.domain.com...] [R=permanent,L]

$1 ended up as the URI relative to the directory, not relative to the root of the subdomain, even though the rule being executed was in the .htaccess in the root directory of the subdomain.

Lesson learned. :)

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members