Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    Regular Coder
    Join Date
    Oct 2008
    Location
    Poland
    Posts
    382
    Thanks
    150
    Thanked 2 Times in 2 Posts

    .htaccess 301 redirect from one page to the other, how to

    Hello, how should look like a redirect rule that does the following:

    redirects all the requests for:

    www.domainone.com/pageone
    www.domainone.com/pageone/
    domainone.com/pageone
    domainone.com/pageone

    to
    domaintwo.com/pagetwo

    ?

  • #2
    Regular Coder poyzn's Avatar
    Join Date
    Nov 2010
    Posts
    266
    Thanks
    2
    Thanked 61 Times in 61 Posts
    put into .htaccess next code
    Code:
    RewriteEngine On
    RewriteCond %{REQUEST_URI} ^/pageone
    RewriteRule . http://domaintwo/pagetwo [R=301]

  • #3
    Regular Coder
    Join Date
    Oct 2008
    Location
    Poland
    Posts
    382
    Thanks
    150
    Thanked 2 Times in 2 Posts
    hello, I tried to request www.domainone.com/pageone with or without /, but it doesn't redirect at all :/

    Is everything right in that rule?

  • #4
    Regular Coder poyzn's Avatar
    Join Date
    Nov 2010
    Posts
    266
    Thanks
    2
    Thanked 61 Times in 61 Posts
    Quote Originally Posted by utnalove View Post
    hello, I tried to request www.domainone.com/pageone with or without /, but it doesn't redirect at all :/

    Is everything right in that rule?
    Yes, I've tested it.

    Is your server running Apache web server?
    Is Apache rewrite module enabled on your server?
    Post here a listing of your .htaccess
    Last edited by poyzn; 07-25-2011 at 11:26 AM.

  • #5
    Regular Coder
    Join Date
    Oct 2008
    Location
    Poland
    Posts
    382
    Thanks
    150
    Thanked 2 Times in 2 Posts
    Hello, domainone is running Apache. Domaintwo is not running Apache, but a webserver that accepts .htaccess and rewriterules and rewriteconds.

    This is the current htaccess in the root of domainone:

    Code:
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    # END WordPress
    
    <Files 403.shtml>
    order allow,deny
    allow from all
    </Files>
    
    
    RewriteCond %{REQUEST_URI} ^/this-is-a-part-of-the-URL
    RewriteRule . http://domaintwo.pl/part-of-URL [R=301]

  • #6
    Regular Coder poyzn's Avatar
    Join Date
    Nov 2010
    Posts
    266
    Thanks
    2
    Thanked 61 Times in 61 Posts
    change it with
    Code:
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{REQUEST_URI} ^/this-is-a-part-of-the-URL
    RewriteRule . http://domaintwo.pl/part-of-URL [R=301]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    # END WordPress
    
    <Files 403.shtml>
    order allow,deny
    allow from all
    </Files>
    and try to load http://domainone/this-is-a-part-of-the-URL
    Last edited by poyzn; 07-25-2011 at 02:02 PM.

  • Users who have thanked poyzn for this post:

    utnalove (07-25-2011)

  • #7
    Regular Coder
    Join Date
    Oct 2008
    Location
    Poland
    Posts
    382
    Thanks
    150
    Thanked 2 Times in 2 Posts
    if I understand well you just changed the position of the two lines, right?

  • #8
    Regular Coder poyzn's Avatar
    Join Date
    Nov 2010
    Posts
    266
    Thanks
    2
    Thanked 61 Times in 61 Posts
    Quote Originally Posted by utnalove View Post
    if I understand well you just changed the position of the two lines, right?
    Yes,

    You've got if statement:
    Code:
    <IfModule mod_rewrite.c> // if rewrite module is on
    
    ...
    </IfModule>
    I've put my code inside.

    Then you have the rule that redirects all requests to index.php, so I've put my rule before it.
    Code:
    RewriteCond %{REQUEST_FILENAME} !-f //if requested file doesn't exist
    RewriteCond %{REQUEST_FILENAME} !-d //if requested directorye doesn't exist
    RewriteRule . /index.php [L]  //then redirect to index.php
    Does it work?
    Last edited by poyzn; 07-25-2011 at 02:38 PM.

  • Users who have thanked poyzn for this post:

    utnalove (07-25-2011)

  • #9
    Regular Coder
    Join Date
    Oct 2008
    Location
    Poland
    Posts
    382
    Thanks
    150
    Thanked 2 Times in 2 Posts
    hmm... it is not redirecting.... with or without slash :/

    Code:
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_URI} ^/part-of-link-part-of-link-part-of
    RewriteRule . http://domaintwo.pl/part-of-link [R=301]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    # END WordPress
    
    <Files 403.shtml>
    order allow,deny
    allow from all
    </Files>
    Last edited by utnalove; 07-25-2011 at 03:06 PM.

  • #10
    Regular Coder poyzn's Avatar
    Join Date
    Nov 2010
    Posts
    266
    Thanks
    2
    Thanked 61 Times in 61 Posts
    oops, sorry, add "L" for the "last" rule
    Code:
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{REQUEST_URI} ^/test
    RewriteRule . http://domaintwo.pl/test [L,R=301]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    # END WordPress
    
    <Files 403.shtml>
    order allow,deny
    allow from all
    </Files>

  • Users who have thanked poyzn for this post:

    utnalove (07-25-2011)

  • #11
    Regular Coder
    Join Date
    Oct 2008
    Location
    Poland
    Posts
    382
    Thanks
    150
    Thanked 2 Times in 2 Posts
    Excellent!!! Thank you


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •