Forum Moderators: phranque

Message Too Old, No Replies

best practice for SEF pages

with 1000 combinations

         

smithydude

4:50 pm on Apr 21, 2009 (gmt 0)

10+ Year Member



Looking for the following pages to be created:

www.example.co.uk/find/roses/london/
www.example.co.uk/find/roses/edinburgh/
www.example.co.uk/find/lilies/edinburgh/
...
...

with 20 types of flowers and 50 locations - so 1000 "pages" in total

In the .htacccess in the find folder I have the following:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.co\.uk [NC]
RewriteRule (.*) http://www.example.co.uk/find/$1 [R=301,L]

RewriteRule ^([a-zA-Z]+)/$ /find/view.php?trade=$1 [L]
RewriteRule ^([a-zA-Z]+)/([a-zA-Z]+)/$ /find/view.php?trade=$1&loc=$2 [L]

What is the best practice with regard to checking that URL is valid?

For example:

www.example.co.uk/find/sdf/sdfl/

is currently valid but should not be. Is it sufficient to check "sdf" and "sdfl" against values in a database in view.php, or should this be done using rules in the .htaccess?

Thanks for any help

g1smd

9:17 pm on Apr 21, 2009 (gmt 0)

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



Yes, check the values in the database, and send a 404 HTTP Header for all non-valid values and for all non-valid combinations (i.e when values are valid, but not in *that* combination).

This rule:

RewriteCond %{HTTP_HOST} ^example\.co\.uk [NC] 
RewriteRule (.*) http://www.example.co.uk/find/$1 [R=301,L]

troubles me a bit. I originally wondered what is it supposed to do? I guessed that it likely doesn't do exactly what you planned, nor does it do it for all URLs that need correcting - but then I noticed you said it is located in the /find/ folder, so maybe that isn't so bad after all. Do note that it will not fix a URL with appended port number for "www." hostnames (it will only fix those for non-www requests). There is better code for this.

Note that

([a-zA-Z]+)
simplifies to
([A-Z]+)
when used with the
[NC]
flag.

jdMorgan

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

WebmasterWorld Senior Member 10+ Year Member



The "best code" for domain canonicalization also depends on whether you've got additional domains or subdomains that should *not* be redirected to the same canonical domain. If you've only got example.com.uk and www.example.co.uk, then the rule above could be:

# If not *exactly* www.example.co.uk, redirect to canonical hostname
RewriteCond %{HTTP_HOST} !^www\.example\.co\.uk$
RewriteRule ^(.*)$ http://www.example.co.uk/find/$1 [R=301,L]

Otherwise, you may need to get tricky:

RewriteCond %{HTTP_HOST} ^example\.co\.uk [NC,OR]
RewriteCond %{HTTP_HOST} ^www\.example\.co\.uk(\.¦\.?:[0-9]+)$ [NC]
RewriteRule ^(.*)$ http://www.example.co.uk/find/$1 [R=301,L]

Replace the broken pipe "¦" character with a solid pipe before use; Posting on this forum modifies the pipe characters.

I too am confused as to why this function is being done in the /find folder. Usually, URL canonicalization is done "at the top of the site" in example.co.uk/.htaccess, and applies site-wide. But the code snippets here illustrate the point about FQDN and appended port numbers nevertheless.

Jim

smithydude

9:36 am on Apr 22, 2009 (gmt 0)

10+ Year Member



Great, thanks g1smd.... that's what I'll do :-)

jd, thanks. Your first solution is fine for me.

I still have the following problem: canonicalization (at the top of the site) works for all the site except for the SEF pages that I am creating.

So

example.co.uk becomes www.example.co.uk
but
example.co.uk/find/roses/london/ stays the same

I can resolve this by putting the cononicalization rules into the .htaccess in the find folder (as per my example), but from what you say jd, I expect there nicer solution?

smithydude

8:30 am on Apr 24, 2009 (gmt 0)

10+ Year Member



Anyone have ideas about this?