1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

The same mod_rewrite achieving two different things

Discussion in 'Apache' started by sam_h, May 29, 2009.

  1. #1
    Hi all,

    Here's something that has stumped me today...

    I've added the following very basic mod_rewrite into an htaccess code for two blogs:

    RewriteEngine On

    RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=301,L]

    (obviously changing new domain to for each respective blog)

    On one of the blogs I am achieving the correct effect - each blog post from the old domain is directed to the equivalent blog post on the new domain.

    On the other blog however, it is just redirecting to the index page of the new domain...to the best of my knowledge everything else is the same!!

    Any ideas?! Much appreciated

    Sam
     
    sam_h, May 29, 2009 IP
  2. sam_h

    sam_h Peon

    Messages:
    188
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Ha! apologies I've just worked it out!

    But I'mnot sure why it makes a difference so I'll post the changes here and maybe someone could explain why it has made a difference!

    Here is the mod_rewrite that I had in place that worked as I wanted (see above)

    #<IfModule mod_rewrite.c>
    #RewriteEngine On
    #RewriteBase /directory/
    #RewriteCond %{REQUEST_FILENAME} !-f
    #RewriteCond %{REQUEST_FILENAME} !-d
    #RewriteRule . /directory/index.php [L]
    #</IfModule>

    RewriteEngine On

    RewriteRule ^(.*)$ http://newdomain.com/$1 [R=301,L]

    And here's the one that didn't work:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /directory/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /directory/index.php [L]
    </IfModule>

    RewriteEngine On

    RewriteRule ^(.*)$ http://newdomain.com/$1 [R=301,L]

    Basically, there are no hashes at the beginning of each line of the intial mod_rewrite rules....why does this make a difference?
     
    sam_h, May 29, 2009 IP
  3. Sudoku-Master

    Sudoku-Master Peon

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    the # marks the following in this line as comment... ;-)
     
    Sudoku-Master, May 29, 2009 IP
  4. Lpe04

    Lpe04 Peon

    Messages:
    579
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You can put
    RewriteEngine On
    
    RewriteRule ^(.*)$ http://newdomain.com/$1 [R=301,L]
    Code (markup):
    before
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /directory/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /directory/index.php [L]
    </IfModule>
    Code (markup):
    The RewriteRule in the Ifmodule executes and stops the rest of the code from executing, (before it can redirect).

    Place your rewriterules before the original code and you should be fine.
     
    Lpe04, May 29, 2009 IP