Forum Moderators: phranque

Message Too Old, No Replies

Rewrite help pls - struggliing all day with it.

         

steve_bk

11:47 pm on Jul 19, 2011 (gmt 0)

10+ Year Member



Hello,

I need some help doing an Apache Rewrite Rule I have been struggling all day to get it to work.

Here is what I am trying to do.
www.domain1.com to www.domain2.com/something/page1.html - Have this working no problem.

www.domain1.com/something/page.asp to www.domain2.com/somethingelse/anotherpage.html - Can’t get this to work I always redirect to www.domain2.com/something/page1.html.

So if someone can help me that would be great.

This is what I have tried with many variations today and moving one over the other.

RewriteCond %{HTTP_HOST} ^domain1.com
RewriteRule (.*) [domain2.com...] [R=301,L]
RewriteCond %{HTTP_HOST} ^www.domain1.com
RewriteRule (.*)http://www.domain2.com/something/page1.html [R=301,L]

RewriteCond %{HTTP_HOST} ^domain1.com/something/page.asp
RewriteRule (.*) [domain2.com...] [R=301,L]
RewriteCond %{HTTP_HOST} ^ domain1.com/something/page.asp
RewriteRule (.*)http://www.domain2.com/www.domain2.com/somethingelse/anotherpage.html [R=301,L]

Thanks Again

g1smd

12:18 am on Jul 20, 2011 (gmt 0)

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



The question says "rewrite".

The example code has "redirects".

Which do you want?

You also need to escape literal periods on patterns.

Use example.com to stop the forum auto-linking the URLs.

lucy24

12:21 am on Jul 20, 2011 (gmt 0)

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



Rule #1: use example.com so people can see what you typed. All other urls are auto-converted into clickable links. Admittedly this can be a problem if you're talking about two different domains ;) But I think only domain2.com needs to be re-rendered as example.com since it's the only one prececeded by http

www.domain1.com/something/page.asp to www.example.com/somethingelse/anotherpage.html - Can’t get this to work I always redirect to www.example.com/something/page1.html.

So if someone can help me that would be great.

This is what I have tried with many variations today and moving one over the other.

RewriteCond %{HTTP_HOST} ^domain1.com
RewriteRule (.*) http://www.example.com/something/page1.html [R=301,L]

RewriteCond %{HTTP_HOST} ^www.domain1.com
RewriteRule (.*)http://www.example.com/something/page1.html [R=301,L]

RewriteCond %{HTTP_HOST} ^domain1.com/something/page.asp
RewriteRule (.*) http://www.example.com/somethingelse/anotherpage.html [R=301,L]
RewriteCond %{HTTP_HOST} ^ domain1.com/something/page.asp
RewriteRule (.*)http://www.example.com/www.example.com/somethingelse/anotherpage.html [R=301,L]

Are all spaces exactly as they appear in your htaccess? Spaces have meaning in htaccess, so this is crucial.

And is that last rule really what you typed?

Unless I'm reading it backward, your first two rules between them pick up all possible requests, so there's nothing left for the remaining rules to work on.

steve_bk

12:32 am on Jul 20, 2011 (gmt 0)

10+ Year Member



Sorry, It should be redirects.

Also my example is just that an example. There shouldn't be a space.

RewriteCond %{HTTP_HOST} ^domain1.com/something/page.asp
RewriteRule (.*) [domain2.com...] [R=301,L]
RewriteCond %{HTTP_HOST} ^domain1.com/something/page.asp
RewriteRule (.*)http://www.domain2.com/www.domain2.com/somethingelse/anotherpage.html [R=301,L]

RewriteCond %{HTTP_HOST} ^domain1.com
RewriteRule (.*) [domain2.com...] [R=301,L]
RewriteCond %{HTTP_HOST} ^www.domain1.com
RewriteRule (.*)http://www.domain2.com/something/page1.html [R=301,L]

Even if put in this order it does not work. Also I have tried many variations today non working.

g1smd

12:42 am on Jul 20, 2011 (gmt 0)

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



Use example.com to stop the forum auto-linking the URLs.