Forum Moderators: phranque

Message Too Old, No Replies

mod_rewrite code for URL redirect

         

vwsequeira

1:11 pm on Jun 22, 2006 (gmt 0)

10+ Year Member



Hi,

1)Can you please provide me with the mod_rewrite code which is equivalent to redirect command in .htaccess.

That is ,

redirect /page.html [otherdomain.com...]

2) Redirect the domain to a new destination,

that is

[domainname.com...] should go to [seconddomainname.com...]

3) Redirect the domain to a folder in the same account,

That is

[domainname.com...] should go to [domainname.com...]

Thank you ,

Vincent

jdMorgan

3:57 am on Jun 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Vincent,

I'm sorry, but our forum charter [webmasterworld.com] prohibits writing code-on-demand here; We simply can't support such requests with the small number of contributors we have here. Our purpose is to discuss Apache-related topics, not to serve as a free code-writing service.

Perhaps the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com] will be helpful to you.

Jim

vwsequeira

1:24 pm on Jun 23, 2006 (gmt 0)

10+ Year Member



Thank you Jim,

Can you please help me to redirect the domain to yahoo, actually I am not getting how to do it.

RewriteEngine On
Options +FollowSymlinks
RewriteBase /

RewriteCond %{HTTP_HOST} example.net
RewriteCond %{REQUEST_URI}!yahoo.com
RewriteRule ^(.*)$ yahoo.com/$1 [L]

[edited by: jdMorgan at 2:52 pm (utc) on June 23, 2006]
[edit reason] Exampleified. No URLs, please. See TOS. [/edit]

vwsequeira

1:27 pm on Jun 23, 2006 (gmt 0)

10+ Year Member



Also I am with you guys more than one year. You can see the registration date. But you still display me as a new member?

jdMorgan

2:59 pm on Jun 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



To invoke a redirect, you should use a canonical URL (http://example.com) in the RewriteRule substitution and the [R=301] flag. Also, you should escape any characters that are used as regular-expressions tokens, such as "." by preceding them with "\" in your regex patterns.

RewriteEngine On
Options +FollowSymlinks
RewriteBase /
#
# Redirect requests for pages on example.net to corresponding pages in "folder" on yahoo.com
RewriteCond %{HTTP_HOST} example\.net
RewriteRule (.*) http://www.yahoo.com/folder/$1 [R=301,L]

This code assumes that the new domain is not located on the same server as the old domain.

WebmasterWorld membership levels are based on post count, not on sign-up date.

Jim

vwsequeira

3:13 pm on Jun 24, 2006 (gmt 0)

10+ Year Member



Thank you Jim , I really appreciate your help. You have been great for us all the time

vwsequeira

1:03 am on Jun 29, 2006 (gmt 0)

10+ Year Member



Jim ,

that code you gave earlier works fine , however I used same code to redirect a sub domain to an external URL but it gives just page not found error. There is no issue with the external URL

RewriteEngine On
Options +FollowSymlinks
RewriteBase /
RewriteCond %{HTTP_HOST} subdomain.foo.com
RewriteRule (.*) http://subdomain2.example.net/email/scripts/index.pl/$1 [L]

[edited by: jdMorgan at 2:15 pm (utc) on June 29, 2006]
[edit reason] No URLs, please. See TOS. [/edit]