Welcome to WebmasterWorld Guest from 23.22.182.29

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Redirect adding file names AFTER new file names

     
9:15 am on Feb 24, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:May 6, 2005
posts:863
votes: 0


Hi everyone

I am in the process of moving a fairly large site so need everything to work as good as possible, I have rows of redirect 301 in the htaccess thats going to be uploaded to the old sites root.

The problem I am having after testing it is, it goes to the correct folder on the new site and the correct file BUT it adds the old file name directly after the new file name or folder/

redirect 301 /folder/old.php http......./folder/new.phpold.php

The new folders have their own htaccess which creates friendly URLs' is that the problem? how do I fix it?

Thanks in advance
2:40 pm on Feb 24, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


With Redirect, the remainder of the old path is automatically re-appended.

Use RewriteRule code instead. It gives you more control. Use the [R=301,L] flags.

Be aware that for any requested URL you do NOT want a multiple step redirection chain. Make sure (using the "Live HTTP Headers" extension for Firefox), that the redirect happens in a single step.
2:47 pm on Feb 24, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:May 6, 2005
posts:863
votes: 0


Hi g1smd, thanks for the reply, so do I replace ALL of these

redirect 301 /folder/oldfile.php http:..../folder/newfile.php

with

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /oldfolder/oldfile\.htm
RewriteRule (.*) http:....../newfolder/newfile.php [R=301,L]

And keep it all in the htaccess for of the OLD site, I read somewhere to let the old domain/site do ALL the redirect work

I hope the above is correct and will do what I want it to, thanks again
3:43 pm on Feb 24, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:May 6, 2005
posts:863
votes: 0


Ok the above works for the most part but I have some pages with query strings and I am not getting the correct page name, I am getting the correct content but this happens in the address bar

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /folder/folder/page\.php\?query=TownName
RewriteRule (.*) http:........./folder/in/TownName [R=301,L]

Browser address bar has http:........./folder/in/TownName?query=TownName

its adding ?query=TownName after what I expected, if I get these working then its job done hopefully, thanks for the help
5:16 pm on Feb 24, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


Add a question mark to the redirect target URL to clear the query string.


If there is no query string in the original request you might be able to use the simpler code:

RewriteRule ^oldpath/oldfile$ http://www.example.com/newpath/newfile? [R=301,L]
6:11 pm on Feb 24, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:May 6, 2005
posts:863
votes: 0


Is this correct

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /oldfolder/in/query.php\?query=String
RewriteRule ^oldfolder/in/query$ http:............/newfolder/in/query? [R=301,L]

Browser now shows http:newdomain/oldfoldername/in/query.php?query=String

Did I get it wrong?
7:46 pm on Feb 24, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


Did you clear the browser cache before testing?

Use the "Live HTTP Headers" extension for Firefox to see the server responses.

If the problems persist, you likely have some rules in the wrong order.
8:50 pm on Feb 24, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:May 6, 2005
posts:863
votes: 0


Hi g1smd, I appreciate your continued help, thank you

All thats in my htaccess file is this


Options +FollowSymlinks All -Indexes
RewriteEngine On

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /oldfolder1/oldfolder2/town\.php\?town=TownName
RewriteRule (.*) http://www.newdomain.co.uk/newfolder1/newfolder2/TownName [R=301,L]


Live headers output


http://www.oldomain.com/oldfolder1/oldfolder2/town.php?town=TownName

GET /oldfolder1/oldfolder2/town.php?town=TownName HTTP/1.1
Host: www.oldomain.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13 (.NET CLR 3.5.30729)
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-gb,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
HTTP/1.1 301 Moved Permanently
Date: Thu, 24 Feb 2011 20:32:43 GMT
Server: Apache/1.3.29 (Unix) (Red-Hat/Linux) Chili!Soft-ASP/3.6.2 mod_ssl/2.8.14 OpenSSL/0.9.6b PHP/4.4.9 FrontPage/5.0.2.2510
Location: http://www.newdomain.co.uk/newfolder1/newfolder2/TownName?town=TownName
Content-Type: text/html; charset=iso-8859-1
Age: 0
Connection: close


Browser output

[newdomain.co.uk...]

This ?town=TownName is extra, the browser shows the correct content, this is the nearest I can get, good for users maybe but not for search engines.
9:17 pm on Feb 24, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


There must be something else interfering with this.

The code looks right.

Are there any other .htaccess files in higher lever folders?

Is there any URL rewriting going on anywhere?
7:59 am on Feb 25, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:May 6, 2005
posts:863
votes: 0


Is there any URL rewriting going on anywhere?


Yes, the target URL has a htaccess for seo friendly URLs, hers its content

RewriteRule ^([^./]+)$ /newfolder1/newfolder2/walkin.php?town=$1 [L]


It uses walkin.php to display each towns data, is it getting the TownName twice now? hence the addition to the end of the address, how do I stop that?
9:44 am on Feb 25, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


No. It won't get it twice, because you're replacing whatever it is with
?town=$1
.

The
QSA
flag would re-append the original query string in addition to whatever is already there, but you don't want that.
9:57 am on Feb 25, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:May 6, 2005
posts:863
votes: 0


So can it not be corrected, if not I will just direct all those pages to / (front page of new site) I know its not ideal but probably the way forward.
10:17 am on Feb 25, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


Sure. It can and should be corrected.

You're going to have to find out what piece of code is causing the problem first.

Redirecting all of those pages to root is NOT a solution. It's a sign of "poor technical quality".
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members