Forum Moderators: phranque
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
This rule:
RewriteCond %{HTTP_HOST} ^example\.co\.uk [NC]
RewriteRule (.*) http://www.example.co.uk/find/$1 [R=301,L] Note that
([a-zA-Z]+) simplifies to ([A-Z]+) when used with the [NC] flag.
# 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]
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]
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
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?