ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

mod_rewrite - General Question

February 18, 2010 12:13pm

Subscribe [3]
  • #1 / Feb 18, 2010 12:13pm

    Ambition

    8 posts

    Hi Guys,

    I hope I’m posting this in the right forum. Apologies if not.

    We’re in the process of developing a new site using Expression Engine. The current site has legacy .php and .html files which the client needs to retain (for affiliates etc), however we would like to keep the root www directory sacred - solely used for EE. I’d like to propose moving these over to a subdomain however I’m really not sure if it’s possible to achieve the ‘catch-all’ level of control I’m looking for using mod_rewrite.

    For example:

    Current structure:  http://www.domain.com/affiliates/any/folder/file.php
    I would like to redirect to :  http://sub.domain.com/affiliates/any/folder/file.php

    The important thing to note is that there are many files and folders within the ‘affiliates’ directory so what we’re looking for is a catch-all method of saying ‘anything inside of the affiliates folder, redirect it to this subdomain but keep all of the directory/file references after it’.

    Is there a way of doing this using mod_rewrite?

    I’ve tried the following in an .htaccess file :
    RedirectMatch 301 ^/affiliates/.*$ http://sub.domain.com/affiliates/

    but unfortunately it sent everything to the affiliates directory on the subdomain and didn’t retain the other parts of the URL.

    E.G. http://www.domain.com/affiliates/any/folder/file.php
    became
    http://sub.domain.com/affiliates/  -  /any/folder/file.php was missing

    I hope this makes sense? Is there a way of doing this in Apache? As you can guess, my mod_rewrite knowledge is v.limited.

    Hope someone can help?

    Thanks,
    Gary

  • #2 / Feb 18, 2010 3:42pm

    Ingmar

    29245 posts

    Ambition, this is not really an issue with EE as such. Let me move this thread to Howto for some community support.

  • #3 / Feb 18, 2010 3:49pm

    ender

    1644 posts

    try this:

    RewriteRule ^affiliates/(.*) <a href="http://sub.domain.com/affiliates/$1">http://sub.domain.com/affiliates/$1</a> [R=301,L]
  • #4 / Feb 18, 2010 3:52pm

    Focus Lab Dev Team

    1129 posts

    E.G. http://www.domain.com/affiliates/any/folder/file.php
    became
    http://sub.domain.com/affiliates/  -  /any/folder/file.php was missing

    Sounds like you’re almost there. Try adding a $1 to the end of the redirect (which tells apache to carry over the remaining pieces of the string that it matched in this case)

    RewriteRule ^/affiliates/.*$ <a href="http://sub.domain.com/affiliates/$1">http://sub.domain.com/affiliates/$1</a> [R=301,L]

    Edit: Looks like Ty beat me to this one 😊

  • #5 / Feb 18, 2010 7:02pm

    Ambition

    8 posts

    try this:

    RewriteRule ^affiliates/(.*) <a href="http://sub.domain.com/affiliates/$1">http://sub.domain.com/affiliates/$1</a> [R=301,L]

    This worked perfectly. Thank you so much!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases