Forum Moderators: phranque

Message Too Old, No Replies

Problem redirecting from a method=get form

         

londonhogfan

8:07 pm on Oct 16, 2007 (gmt 0)

10+ Year Member



This forum is great. I have been able to answer almost all of my questions by browsing around. i do have one that I can't find on here though.

Currently my site rewrites my urls from
example.com/years.php?from=1890&to=2007

to
example.com/years/1890-2007

using this in my .htaccess file
RewriteRule ^Years/([^-]*)-([^-]*)$ /Years.php?from=$1&to=$2 [L]

now for my problem...

I have a form on my site that uses method=get so users can enter in a start and end year to get the results - so when someone uses that they will still get the full (non sef) url. Is there a way to redirect every url in that format to the new one so it would go automatically without duplicate pages?

Thanks for the help.

jdMorgan

11:40 pm on Oct 16, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Be aware that you are not rewriting the non-SEF URL to the SEF URL, you are doing the reverse. And this is what is required so that the SEF URLs published (and therefore defined) on your pages can be 'connected' to the script on your server. This may seem trivial, but it is important to understand how and when rewrites are applied. Mod_rewrite takes action on the URL requested by the client, and translates it either into a new URL (for a redirect) or into a server-internal filepath (a rewrite to your script filepath with appended parameters, in this case).

> Is there a way to redirect every url in that format

Sorry, but what format? It's a bit difficult to answer without an example. :)

Jim

londonhogfan

12:11 am on Oct 17, 2007 (gmt 0)

10+ Year Member



<snip>

{My site] automatically gives the results for every [team] football game from 1894-2007. The user can also pick a range of years from the form on the right column. I have used mod_rewrite to make the urls look like this.
http://www.example.com/YearlyResults/1990-1997
instead of
http://www.example.com/YearlyResults.php?from=1990&to=1997

The only problem is when I use the form it still sends you to the original url with the?from=year&to=year instead of the shortened version. Is it possible to forward those results to the correct rewritten page using .htaccess?

So it will alway redirect
yearlyresults.php?from=xyz&to=yyyy
to
YearlyResults/xyz-yyyy

Thanks for your help.

[edited by: jdMorgan at 5:14 pm (utc) on Oct. 17, 2007]
[edit reason] No personal domains or searchable terms, please. [/edit]

jdMorgan

5:16 pm on Oct 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Using redirects is not the correct or most beneficial way to handle this. Properly done, a redirect is only used as an optional final step in the process.

This thread [webmasterworld.com] describes the three-step process, including changing the links on your pages and mod_rewrite code, to implement search-engine-friendly URLs.

Jim

londonhogfan

7:44 pm on Oct 17, 2007 (gmt 0)

10+ Year Member



well if I understand it correctly I have completed the first two steps.

I have setup the .htaccess file to rewrite dynamic pages into the format I want - All of my links are (or will be) setup to the new SEF urls. I'm having trouble with the 301 redirect on dynamic pages though. I have done 301 on my pages that stay the same each time.
ex. example.php?board=a to /board/a/ but can't find how to redirect items that would change. Do I have to setup a 301 for every possible combination of requests?
Example... Everytime someone puts in a link to Yearly.php?from=A&to=B it would transfer them to yearly/A-B. I have no problem putting in that one combination, but what if they put in A-C or C-F do I have to put a redirect to all of them or is there a shorter way to do it?

The only time It will even go to the dynamic url is when someone uses a form to get the years - I can't figure out how to make a form return a url such as 2000-2007 instead of?from=2000&to=2007.

jdMorgan

7:50 pm on Oct 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You must change your pages to include the new pretty links by editing them (or your page-generation script) -- A redirect in .htaccess won't do. The cited thread is detailed and specific, so read very carefully.

You can use regular-expressions pattern-matching and 'back-references' to make one rule handle many combinations of URL-path elements and query-string values. This is also demonstrated in the cited thread.

Jim