Forum Moderators: phranque

Message Too Old, No Replies

3 partial file name change rewrite senario's I would like to learn for

Need htaccess rewrite advice

         

kmb123

4:20 pm on Dec 21, 2009 (gmt 0)

10+ Year Member



htaccess rewrite

I have many web page files under a old brand name I need to change without loosing my incoming links to these old pages, is there a way I can do this with my htaccess file using the senario's below so that my renamed files still are found from old links?

3 rewrite senario's I would like to learn

how do I remove part of file name(s) (eliminate oldbrand-)
[domain.com...] to [domain.com...]

how do I replace part of file name(s) (oldbrand- to newbrand-)
[domain.com...] to [domain.com...]

How do I remove part of file name(s) and add directory
[domain.com...] to [domain.com...]

Any help would be appreciated, please provide htaccess text code for each senario above if you can... Thanks To All!

Keith

g1smd

5:10 pm on Dec 21, 2009 (gmt 0)

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



That depends on how the old name and new name are related.

If it is a case of changing many URLs in exactly the same way, then Mod_Rewrite might be able to help.

If the two names are unrelated, you'll need to rewrite the old requests to an internal script file that then does a database lookup to find the new name, the script then sending the HTTP headers.

So, the question as originally phrased is far too vague to even begin to start coding. The requirements haven't been *fully* and intricately documented.

In any case, we need to see your code. We can help you fix your code, but there are not enough volunteers to provide a free code writing service in this forum.

jdMorgan

5:24 pm on Dec 21, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's good to provide a 'generic' description of the goals as you did in your first post, but we also need to see some concrete example URL-paths -- and further, those concrete example URL-paths need to be as different from each other as possible, in order to illustrate all possible variations in the requested URLs such as characters used, lengths of fields within the URL-paths, etc.

The basic form of a RewriteRule for redirection is


RewriteRule ^old-url-path$ http://www.example.com/new-url-path [R=301,L]

But that requires one rule per old URL. In order to make one rule properly handle more than one old URL, all of the details of the form and allowable possible variations of the old URLs are needed. This is because mod_rewrite is based on pattern-matching, so the patterns must be exact and comprehensive -- neither too 'accepting' nor too selective for your URLs.

Jim

kmb123

7:26 pm on Dec 21, 2009 (gmt 0)

10+ Year Member



my changes are all related to the (oldpage-) part of the url
[domain.com...]
[domain.com...]
[domain.com...]
[domain.com...]

Just wondering if I can redirect in the 3 senerio's given to go to

[domain.com...]
[domain.com...] etc...
or
[domain.com...]
[domain.com...] ect...

it's just the oldpage- part that I want to change to many files by renaming or shortening and moving to a folder

kmb123

7:30 pm on Dec 21, 2009 (gmt 0)

10+ Year Member



point is I want to redirect like one folder to another
Redirect 301 /oldfoder [domain.com...]
but instaed changing part of the file name that is alike in each of these files

kmb123

7:45 pm on Dec 21, 2009 (gmt 0)

10+ Year Member



more clearly, I want to
change the (oldbrand-)part of many urls that is the same in each url by either eliminating it, changing it or, eliminating it and redirecting to a folder where the new files with the (oldbrand-) section of the url removed from each file would reside.

g1smd

10:08 pm on Dec 21, 2009 (gmt 0)

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



In your pattern, capture the part that is going to be re-used as a back-reference, and discard the other part. However, some fine details like 'are the two parts delinated by a hyphen' are crucial to how the actual code will look.

RewriteRule ^oldstuff-(.*) http://www.example.com/newstuff-$1 [R=301,L]

This redirects

/oldstuff-anything to www.example.com/newstuff-anything

It's all about the patterns. Those need to be carefully defined. In many cases using

.*
will not be acceptable.

kmb123

4:05 am on Dec 22, 2009 (gmt 0)

10+ Year Member



superb... worked perfectly, thanks so much!