...

View Full Version : .htaccess 301 redirect from one page to the other, how to



utnalove
07-24-2011, 09:11 PM
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

?

poyzn
07-25-2011, 08:10 AM
put into .htaccess next code


RewriteEngine On
RewriteCond %{REQUEST_URI} ^/pageone
RewriteRule . http://domaintwo/pagetwo [R=301]

utnalove
07-25-2011, 09:48 AM
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?

poyzn
07-25-2011, 12:23 PM
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

utnalove
07-25-2011, 12:32 PM
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:


# 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]

poyzn
07-25-2011, 02:59 PM
change it with


# 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

utnalove
07-25-2011, 03:05 PM
if I understand well you just changed the position of the two lines, right?

poyzn
07-25-2011, 03:36 PM
if I understand well you just changed the position of the two lines, right?

Yes,

You've got if statement:


<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.


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?

utnalove
07-25-2011, 03:44 PM
hmm... it is not redirecting.... with or without slash :/


<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>

poyzn
07-25-2011, 04:01 PM
oops, sorry, add "L" for the "last" rule


<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>

utnalove
07-25-2011, 04:05 PM
Excellent!!! Thank you :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum