Tricky rewrite problem and IE

I have a Joomla site (so it has it’s own rewrite rules) and in there I need to redirect a directory to a new domain. I’ve tried several different things: rewrite rules, meta refresh, etc. And either IE doesn’t like it or the Joomla rules get in the way. Basically this is what I’m trying to do:

[B]redirect http://www.site1.com/directory => https://subdomain.site1.com/directory.html[/B]

this is what I have so far, the last 2 lines are Joomla’s:


Redirect 301 /directory/ https://subdomain.site1.com/directory.html

RewriteCond %{HTTP_HOST} !site1.com$ [NC]
RewriteRule ^(.*)$ http://www.site1.com/$1 [L,R=301]

the problem is this, in IE it redirects to https://subdomain.site1.com/directory.html/, which obviously causes a 404. I’ve tried the Redirect 301 several different ways, tried RedirectMatch as well, with about the same result. It works fine in FF or Chrome, but adds a trailing slash in IE.

The other issue is for some reason, again in IE only, a meta refresh tag in an index page inside the directory gets caught up in the Joomla rewrite rule and doesn’t forward on. Not sure if this means anything or not, but the subdomain is on a different Windows server than the main domain’s Linux server.

edit: Let me add, this is a request from my client, they want to do some direct mail with this URL since it’s a little easier to type rather than the long subdomain URL.

Any help would be much appreciated!

here’s what I have so far:


RewriteCond %{HTTP_HOST} !domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]

RewriteRule ^directory/(.*)$ https://sub.domain.com/directory.html [R=301,L]

which works some of the time, but will still add the trailing slash at the end if the domain is http://www.domain.com/directory/, but not always! how strange…

figured it out, I’m sure there might be a more elegant way, but this seems to work and nothing is broken elsewhere


RewriteRule ^directory(.*)$ https://sub.domain.com/directory.html [R=301,L]
RewriteRule ^directory/(.*)$ https://sub.domain.com/directory.html [R=301,L]\\

RewriteCond %{HTTP_HOST} !domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]


RewriteRule ^directory https://sub.domain.com/directory.html [R=301,L]

RewriteCond %{HTTP_HOST} !domain\\.com$ [NC]
RewriteRule .? http://www.domain.com%{REQUEST_URI} [L,R=301]

Bill,

Your first two RewriteRules “play” with the regex unnecessarily (and you’ve got a typo, an / after the flags) so l_e’s solution is better and should handle your problem adequately.

BTW, the (.*) will also match / and any other garbage you throw at it (including NOTHING) so your RewriteRules are redundant.

Regards,

DK