Forum Moderators: coopster
Am also using .htaccess to rewrite the URLS.
The URLS will be dynamically generated so doing manually each time a new one gets added to the DB could become a bit tedious.
I am a bit stumped...
So as page and Page are getting you to the same place I would guess that this is a windows OS system running Apache. As windows will treat page and Page as the same thing.
You could try Apache's mod_speling, as this should make URL's case insensitive. Although there must be a better method, so I would ask on the Apache forum.
As you are running through php could you not just use something like-
$page = strtolower($input);
# Internally rewrite search engine friendly static URL to dynamic filepath
#and query
RewriteRule ^town/([^/]+)/?$ accommodation.php?town=$1 [L]
RewriteRule ^town/([^/]+)/([^/]+)/?$ accommodation.php?town=$1&company=$2 [L]
# Externally redirect client requests for old dynamic URLs to equivalent new static URLs
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /accommodation\.php\?town=([^\ ]+)\ HTTP/
RewriteRule ^accommodation\.php$ http://www.example.com/accommodation/town/%1? [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /accommodation\.php\?town=([^&]+)&company=([^\ ]+)\ HTTP/
RewriteRule ^accommodation\.php$ http://www.example.com/accommodation/town/%1/%2? [R=301,L]
I am also querying MySql to find a result set WHERE town like "%$_GET['town']%" - wonder if that has anything to do with it too.
[edited by: dreamcatcher at 8:59 am (utc) on April 30, 2008]
[edit reason] use example.com. Thanks. [/edit]
company name - normal stored as - John's Widget Company
and
company_name_fix - a "fix" stored as - johns-widget-company
I use the fix in the url anchor tag but if I change all the first characters, and I suspect the entire case of the word to Johns-Widget-Company or JOHNS-WIDGET-COMPANY - it works fine.
I was hoping an .htaccess fix could switch case of url and 301 any caps urls to the lower case version of the company name that could be 1, 2,3,4,5,6 or more words.
Am I clear or just confusing the issue?
As you are searching for "%$_GET['town']%" that will give you-any number of characters, followed by the GET string, followed by any number of characters.
So if you used strtolower($_GET['town']); then you could guarantee that both Place and place will result in the same query.
If you want all of the GET array in lowercase then you can use array_walk [uk3.php.net] to speed up the process.
I am concerned about when a user might enter the url in the address bar as [site.com...]
The url stays as that - [site.com...]
I'd like the url to change to
[site.com...]
That way I can avoid uppercase manual input and uppercase links people might create unknowingly or maliciously. To avoid duplicate content issues.
I agree. The only solution available in .htaccess is a very slow and inefficient character-by-character rewrite. In addition, multiple case-conversion rewrites trigger a bug in Apache mod_rewrite, which must be worked-around, further reducing efficiency.
I'd recommend that you detect incorrect case in your script, and generate and send a 301-Moved Permanently header with the correct URL.
Jim
As allowing a person to type London or london will make no difference to the end result of your search.
Bots will only index pages that you are linking to, so you will be internally linking to pages with lower case names. So there will be no issue with duplicate content, unless other people link to your site with upper case names.
If you want to 'force' lower case names then you could run the GET string through a filter and
if ($_GET['town'] !== strtolower($_GET['town'])) {
header(Location: strtolower($_GET[town']), true, 301);
}
Is that a bit more what you wanted?
<edit>
Well I was going to suggest asking on the apache forum...but I think the above says that it isnt worth it.
[edited by: PHP_Chimp at 1:17 pm (utc) on May 1, 2008]
Two words: "Duplicate content"
Each page on your site should be directly-accessible via one and only one URL. Any and all variations of that canonical URL should result in a 301-Moved Permanently redirect to the canonical URL.
Jim
== means same as, so 2 == '2' (the integer 2 and the string 2) are the same.
=== means identical, so 2 === '2' is wrong. As although they are the same value they are not of the same type (1 is an integer the other is a string).
I generally try to use identical when testing variables. Although not really necessary, it is just something that I do.
The only solution available in .htaccess is a very slow and inefficient character-by-character rewrite. In addition, multiple case-conversion rewrites trigger a bug in Apache mod_rewrite, which must be worked-around, further reducing efficiency.
Of course you can choose either method, although I know which one I would choose ;)
What I have also added is to check that the $_GET also returns a result set or else send a 404 and then I also check in another case that the $_GET is numeric and if not, return a 404. If it is numeric, get the result array, if result array is empty then throw a 404, if not display, so I have a whole battery of checks!
The only thing I am struggling with now is, my page only works if example.php?id=4 where 4 is a valid place. If you go to example.php on it's own it just displays a blank page which I would like to avoid. Working on that but I am also working on this beer so the beer takes precedent for now...
[edited by: Pico_Train at 8:16 pm (utc) on May 17, 2008]