SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard bbolte's Avatar
    Join Date
    Nov 2001
    Location
    The Central Plains
    Posts
    3,304
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question 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:

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

    this is what I have so far, the last 2 lines are Joomla's:
    Code:
    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!
    Last edited by bbolte; Aug 17, 2012 at 06:52. Reason: adding description

  2. #2
    SitePoint Wizard bbolte's Avatar
    Join Date
    Nov 2001
    Location
    The Central Plains
    Posts
    3,304
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here's what I have so far:
    Code:
    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...

  3. #3
    SitePoint Wizard bbolte's Avatar
    Join Date
    Nov 2001
    Location
    The Central Plains
    Posts
    3,304
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    figured it out, I'm sure there might be a more elegant way, but this seems to work and nothing is broken elsewhere
    Code:
    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]

  4. #4
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Code:
    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]
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  5. #5
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,653
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    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
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •