Forum Moderators: phranque

Message Too Old, No Replies

problem with mod rewrite RewriteRule

         

Tabi

1:18 pm on Sep 22, 2011 (gmt 0)

10+ Year Member



I have this:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^pref\.example\.com$ [NC]
RewriteRule ^(.*)$ http://pref.another.domain.com/$1 [L,R=301]
....


When I navigate to
http://pref.example.com
I am redirected to:
http://pref.another.domain.com/pref/


But I want to be redirected just to
http://pref.another.domain.com


How to achieve this, is something wrong with my rewrite rule?

g1smd

7:06 pm on Sep 22, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Use the Live HTTP Headers for Firefox extension to examine what happens.

Is there a double redirect for this request?

lucy24

8:36 pm on Sep 22, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If your rule is intended to take any request for something in domain#1, and redirect to the same location in domain#2, it is doing exactly what you intended. But if you ask for

domain#1/

alone, and you're being redirected to

domain#2/morestuff

then you have to find where that final /morestuff is coming from.

Tabi

6:59 am on Sep 23, 2011 (gmt 0)

10+ Year Member



These are the first 3 lines of my headers.

http://pref.another.domain.com/pref/login.php
GET /pref/login.php HTTP/1.1
Host: another.domain.com
.....
.....


I am typing:
http://pref.example.com/login.php

I am being redirected to:
http://pref.another.domain.com/pref/login.php


No clue where the
/pref/
suffix is coming from. I managed with this by just copying all files to /pref/ directory in my site root and now the site works, but the
/pref/
suffix shouldn't be added automatically by Apache.

lucy24

7:15 pm on Sep 23, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Apache doesn't take independent action. It only does what you tell it to do-- but what you tell it to do is not always what you meant to tell it.

If you're going cross-eyed trying to figure it out, step back and ask your text editor to find all occurrences of pref/ and \bpref\b in your htaccess. Make sure each one is doing what it's supposed to be doing and only what it's supposed to be doing.

This is assuming you only have one htaccess, and there's nothing going on in your config file. Since you're starting with someone else's generic code (hence the "<If..." elements) there may be stuff you didn't notice.

Come to think of it, all those "If" lines should probably be deleted. Not the whole package, just the "if" and "endif" or "/if" or whatever it's called. You are now in your own specific htaccess, which means that each given module either is or is not present, and the htaccess can be written accordingly.

While you're at it, look at the .php files and make sure they're not doing anything they weren't supposed to.

Oh, and... Is that the very beginning of your headers when you first arrive at the other domain? Make sure there's nothing in the second domain's htaccess that's rerouting you again.

g1smd

7:42 pm on Sep 23, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



When using Live HTTP Headers don't look at what your browser asked for in the first request. You know what you asked for, you typed it in.

Look at the server response to that first request. Is it a redirect? Is it a 301 or 302 redirect? What is the URL you are being redirected to?

Now look at the second request and the response to it. What is that response? Is it another redirect? If it is, is it a 301 or 302 redirect? What is the target URL for this redirect?