Forum Moderators: phranque

Message Too Old, No Replies

Somewhat complicated temporary redirect

setting up temporary redirect with parameters included

         

denny911

4:39 pm on Nov 18, 2009 (gmt 0)

10+ Year Member



Hi folks, I'll try to be as much precise as possible, and include some examples of what i want to achieve.

Since in many of my urls i have characters like čćđžš, i want to use SEO version of those letters (c,c,d or dj, z, s). i'll make an extra field in my db and that's ok.

now, i want to have urls like this (many combinations are possible):

www.example.com/show.php?cat=1&make=Toyota

www.example.com/show.php?cat=1&make=Toyota&model=Avensis

www.example.com/show.php?cat=1&make=Toyota&model=Avensis&color=white

www.example.com/show.php?cat=1&make=Toyota&model=Avensis&color=white&page=4

NOTE: currently, i'm interested in making SEO friendly only this "make" parameter. My redirects should also be working if the parameter is omitted, eg.

www.example.com/show.php?cat=1&make=&model=Avensis&color=white

(although this is not a very good example (since no other make has model Avensis), i think you got the idea)

The reason i want to make temporary redirection is Google. I dont want my visitor get stuck with blank page.

So, if anyone here has any idea, I'll appreciate it a lot!
Thanks!

Paul_Winter

7:22 pm on Nov 18, 2009 (gmt 0)

10+ Year Member



I am personally a little confused, what are you trying to redirect from and to?

I understand that you are trying to make your URLs SEO friendly, but these examples are not. They may be more SEO friendly than your current set up, but still need some work.

Can you display your site for reference?

jdMorgan

10:20 pm on Nov 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



We don't allow URLs or specifics to be posted here -- for the protection of WebmasterWorld, its members, and the person posting links and/or specifics...

We simply need a 'map' of some 'old URLs', the corresponding 'new' URLs, and the server filepaths to which they are to be resolved.

Then we need to see the code you've tried to implement, and a description of how it goes wrong.

If any of the above is unclear, please refer to our Forum Charter.

Thanks,
Jim

g1smd

10:19 am on Nov 19, 2009 (gmt 0)

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



I would suggest that users should be seeing, clicking, and using URLs like:
www.example.com/cat/toyota/avensis/white/4

Note: all lower-case, folder-like URLs, no cruft, no query-string parameters. Use + or - (never hyphen or space) for multi-word values.

Mod_Rewrite is the right tool to make that happen.

denny911

2:26 pm on Nov 19, 2009 (gmt 0)

10+ Year Member



well, the urls i wrote as just examples, not the real ones.

let me try this way. i want to tell .htaccess to redirect temporarily (until google indexes changed URLs) an url like this:

example.com/show.php?cat=1&make=Škoda

to

example.com/show.php?cat=1&make=Skoda

because i want only english alphabet characters a-z in my URLs

after i resolve this issue, i'll try to make all my urls SEO friendly, ie. example.com/show/cat/1/make/skoda/, but only after Google indexed my new URLs

hope this helps
Thanks

jdMorgan

2:53 pm on Nov 19, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You'll likely need to use a RewriteCond to examine the request exactly as received from the client and before any decoding is applied, in order to 'catch' these encoded characters. An example, although the encoded character is not likely correct, would be:

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /show\.php\?cat=1&make=\%23269;koda\ HTTP/
RewriteRule ^show\.php$ http://example.com/show.php?cat=1&make=Skoda [R=301,L]

Note here that the query string appended to the URL-path is not 'visible' to RewriteRule. Also note that the spaces and question mark must be escaped in the RewriteCond pattern. Further, the "#" may be URL-encoded as "%23", and if so, then the "%23" will need to be escaped as shown. The "269;" is likely not correct, and should be changed to the correct code for an HTML-entity of "Š".

A "shortcut" to determine the proper pattern for the RewriteCond would be to look at your raw server access log file, copy the client-requested URL+query string from there, and then apply the required regular-expressions escaping to it. Note that the "[A-Z]+" subpattern is intended to match the HTTP method in the request line, such as "GET", and the unanchored "\ HTTP/" subpattern at the end of the pattern is intended to match either " HTTP/1.0" or " HTTP/1.1" at the end of the client request line.

Jim

g1smd

3:29 pm on Nov 19, 2009 (gmt 0)

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



after I resolve this issue, I'll try to make all my URLs SEO friendly, i.e. example.com/show/cat/1/make/skoda/, but only after Google indexed my new URLs

After they have indexed your "new" URLs they will have to scrap all that and the re-index your yet newer friendly URLs from scratch.

You'll then need to set up two sets of redirects: one for the oldest URL format, and another for this intermediate URL format that you are proposing in this thread.

That is double the work for you, and double the risk of your rankings tanking, due to either some technical mistake and/or Google taking exception to the content moving to a new URL and then moving again shortly after.

I would recommend moving to new friendly URLs now, and adding redirects for all non-canonical formats so thet you move once and only once.

I am not sure that a temporary redirect is what you want either. I would suggest that all of the redirects be permanent i.e. 301. Or, do you mean by 'temporary' that you only want the redirect in place for a short time?

denny911

9:51 pm on Nov 22, 2009 (gmt 0)

10+ Year Member



well, thank you all for help

@jdMorgan, i managed to get all right as you suggested.
but, there's a catch, i dont know how big or small it might be.

it would be very difficult to address every possible parameter combination. is there any way of telling the script that i want only one parameter ("make") matched, no matter how many other parameters there might be after (or somewhere else) it?

for now, im able to match this:
example.com/show.php?cat=1&make=Škoda with
example.com/show.php?cat=1&make=Škoda

but when there is such an url:
example.com/show.php?cat=1&make=Škoda&model=Superb, i want it to redirect to the proper url without having to explicitly saying to the engine which other parameters are and what combination of them might occur.

in other words, i want only a portion (ie, the crucial part) of url to be matched.

Hope you get it. if not, feel free to ask.
Thanks man!

EDIT:
here's a working example:
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /prikazi\.php\?ktg=1&djelatnost=Poljoprivreda\+\-\+Ribarstvo\+\-\+\%C5\%A0umarstvo\ HTTP/

RewriteRule ^prikazi\.php$ [blah-blah.net...] [R=301,L]

jdMorgan

11:38 pm on Nov 22, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sticking with the previous complete example above, you'd capture any and all query parameters before "make=%23269;koda" as well as any that follow, and then re-use them in the output:

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /show\.php\?(([^&\ ]+&)*)make=\%23269;koda((&[^&\ ]+)*)\ HTTP/
RewriteRule ^show\.php$ http://example.com/show.php?[b]%1[/b]make=Skoda[b]%3[/b] [R=301,L]

Jim

denny911

10:52 pm on Nov 25, 2009 (gmt 0)

10+ Year Member



@jdMorgan
Thank you very much - that solved my problem.
later i'll examine the possibility of complete URL change and i'm going to need help again. hope you'll be here again!
cheers!