Uppercase and lowercase urls in PHP - url

I have created folders in my root example: http://www.zipholidays.co.uk/Cuba or http://www.zipholidays.co.uk/Florida
When I type http://www.zipholidays.co.uk/cuba (Cube in lowercase), it shows page not found.
I'm using Apache server. People are linking to pages with lowercase, uppercase, mixed case - whatever. What do I do to make the pages case insensitive?

mod_spelling perhaps? mod_spelling

If you make your pages case insensitive, you'll have some duplicate content problems as you will have two pages with the same content.
A good solution would be to do some 301 redirect on every 404 page when the equivalent in lowercase exists.
For example in your 404 default page, you put :
<?php
$lower = strtolower($_SERVER['REQUEST_URL']);
if (file_exists(PATH_TO_YOUR_APPLICATION . $lower) {
header('location: ' . $lower, true, 301);
die();
}
?>
So when you load a 404 page, if the same url in lower cases exists, you redirect there. Otherwise you can display your own missing page content.

I wouldn’t make my URLs case insensitive. Instead I would follow a strict guideline for creating such URLs. I would for example only use lowercase URL paths and redirect requests with URL paths with uppercase letters to the lowercase variant.
You can even do that with mod_rewrite (requires rewrite map to internal tolower function):
RewriteCond %{tolower:%{REQUEST_URI}} .+
RewriteRule ^[^A-Z]*[A-Z] %0 [L,R=301]

Maybe you can replace linux for windows as the server OS.
Apache on Linux is case sensitive in the filepaths, so also in the URI's. Windows file system isn't case sensitive, so it doesn't matter there.

You do not need to do that. Because Google will think that you have duplicate pages on your site, and gonna ban you. It is the rule of SEO science.

Related

Does letter casing of directories and urls matter in .NET MVC?

Say I have a TitleCase directory name, but call an item within that directory using a lowercase url.
Does that have any effect or impact?
For example, does the server need to do a redirect from the incorrect lettercase to the correct lettercase?
Example
A file here: /PlugIns/CMSPages/Images/my-image.jpg
Called with: /plugins/cmspages/images/my-image.jpg
The routing engine isn't case sensitive.
One thing to be wary of, if you are referring to page urls - Google treats lowercase and uppercase urls as different pages, so you want to make use of rel="canonical" to ensure Google and other search engines know it is one page, no matter whether the url is upper or lowercase.

hide url directory

I have a website:
www.mydomain.com/subfolder/subfolder/index.php
How could always hide the directory names from the url. I mean always hide the 2 subfolders' names from the url as the page changes.
Example:
These urls:
www.mydomain.com/subfolder/subfolder/index.php
www.mydomain.com/subfolder/subfolder/about.php
www.mydomain.com/subfolder/subfolder/contact.php
...
Becomes:
www.mydomain.com/index
www.mydomain.com/about
www.mydomain.com/contact
...
I want to use the last mentioned urls for requesting these pages, too, without typing a horrible long url.
you can find some good hints when you will look for mod_rewrite or mod rewrite in htaccess.
If you have access to the Rewrite engine, you can use a simple rewriting pattern similar to this:
RewriteRule ^/(.*)$ /subfolder/subfolder/$1.php

Rewrite to case insensitive urls in CodeIgniter site?

I'm using CodeIgniter for a web application, and now I have an urgent question: I just discovered that urls are case sensitive in Linux based servers, and I have just moved a site from Windows to Linux. This means links to the site don't work anymore where there are now all lower-case urls, which were not before.
Googling I found that you should be able to do something like this in the .htaccess file:
RewriteMap lc int:tolower
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule (.*) ${lc:$1} [R=301,L]
But I tried that and it was not good at all...! Suddenly I got a big ugly error page staring at me instead, saying that there must be something wrong with the Tomcat server or something like that. Needless to say I removed those lines immediately!
But why didn't it work then, and what should I do instead?
Any help would be greatly appreciated.
Code igniter supports regular expressions - if you'd like to be explicit in the definition of your routes, define them in this fashion to be case insensitive:
$route['(?i)(about\/contact)'] = 'about/contact';
If case insensitive routes are required, do below changes to URI.php
Location of File: system/core/URI.php
Find $this->_parse_request_uri() and replace it with strtolower($this->_parse_request_uri())
Actually found out that it was quite easy, surprised that no one answered this (perhaps it isn't the correct way, but I would think so...):
I just added some routes in the routes.php file in the config folder:
$route['About/Contact'] = "about/contact";
And so on...

SO like URL with mod_rewrite

I want to get a URL scheme exact like SO's question URL.
Like http://stackoverflow.com/questions/6035363/so-like-url-with-mod-rewrite
this page can be accessed with http://stackoverflow.com/questions/6035363
but then it redirects to the http://stackoverflow.com/questions/6035363/so-like-url-with-mod-rewrite
I need to do the same.
My page will be in the root directory named article.php
the url will be like
article.php?id=1&title=some_text
i want it to be accessed with [any of these will do]
acticle.php/id/1/some_text
or
acticle/id/1/some_text
or
acticle/id/1&title=some_text
[Sorry i really dont know about mod_rewrite so i read some question and googled some cheat sheets but none of them worked :(
So looking for some copy-paste solution]
It's best if you divide and conquer the URL to reverse engineer it.
So a few key points:
6035363 is the important part of the URL as it's the question ID.
Everything else is arbitrary SEO, friendly URLs
Having multiple URLs of the same page will hurt SEO, so stick to one URL format
With that said, article/id/some_keyword_text is the format I suggest. The following RewriteRules will handle it.
RewriteEngine On
RewriteBase /
RewriteRule ^article/(\d+)/?$ test/article.php?id=$1 [L]
RewriteRule ^article/(\d+)/([\w-]+)/?$ test/article.php?id=$1&title=$2 [L]
The first rule redirects article/id with an optional trailing slash. The second rule redirects article/id/some_keyword_text with an optional trailing slash. some_keyword_text may only contain alphanumeric, underscore, or dash characters.
Note: The redirection for URLs of format article/id happens at the page level. So this is not a RewriteRule, but logic in the page that redirects when title is not set. I'm guessing a 301 Redirect to ensure point #3.

Redirect 301 with hash part (anchor) #

One of our website has URL like this : example.oursite.com. We decided to move our site with an URL like this www.oursite.com/example. To do this, we wrote a rewrite rule in our Apache server that redirect to our new URL with a code 301.
Many websites link to us with URLs of the form example.oursite.com/#id=23. The problem is that the redirection erase the hash part of the URL with IE. As far as I know, the hash part is never sent to the server.
I wanted to implement the redirection with javascript to keep the hash part, but the Search Engine will not be aware that our URL changed. (no code 301 returned)
I want the Search Engine to be notified of our new URL(301) because we need to transfer the page rank to our new URL.
Is there a way to redirect with a 301 code and keep the hash part(#id=23) of in the URL ?
Search engines do in fact care about hash tags, they frequently use them to highlight specific content on a page.
To the question, however, anchor locations are unfortunately not sent to the server as part of the HTTP request. If you want to redirect a user, you will need to do this in Javascript on the client side.
Good article: http://web.archive.org/web/20090508005814/http://www.mikeduncan.com/named-anchors-are-not-sent/
Seeing as the server will never see the # (ruling out 301 Redirects) and Google has deprecated their AJAX Crawling scheme, it seems that a front-end solution is the only way!
How I did it:
(function() {
var redirects = [
['#!/about', '/about'],
['#!/contact', '/contact'],
['#!/page-x', '/pageX']
]
for (var i=0; i<redirects.length; i++) {
if (window.location.hash == redirects[i][0]) {
window.location.replace(redirects[i][1]);
}
}
})();
I'm assuming that because Google crawlers do indeed execute Javascript, the new pages will be indexed properly.
I've put it in a <script> tag directly underneath the <title> tag, so that it get executed before any other JS/CSS. Note that this script should only be required for your index file.
I am fairly certain that the hash/page anchor/bookmark part of a URL is not indexed by search engines, and therefore has no effect on your page ranking. Doing a google search for "inurl:#" returns zero documents, so that backs up my assumption. Links from external sites will be indexed without the hash.
You are right in that the hash part isn't sent to the server, so as far as I am aware, there isn't a good way to be able to create a redirection url with the hash in it.
Because of this, it's up to the browser to correctly manage the hash during a redirect. Firefox 3.5 appears to do this successfully. If you append a hash to a URL that has a known redirect, you will see the URL change in the address bar to the new location, but the hash stays on there successfully.
Edit: In response to the comment below, if there isn't a hash sign in the external URL for the part you need, then it is entirely possible to rewrite the URL. An Apache rewrite rule would take care of it:
RewriteCond %{HTTP_HOST} !^exemple\.oursite\.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) http://www.oursite.com/exemple/$1 [L,R]
If you're not using Apache, then you'll have to look into the server docs for something similar.
Google has a special syntax for AJAX applications that is based on hash URLs: http://code.google.com/web/ajaxcrawling/docs/getting-started.html
You could create a page on the old address that catches all requests and redirects to the new site with the correct address and code.
I did something like that, but it was in asp.net, which I guess it's not the language you use. Anyway there should be a way to do this in any language.
When returning status 301, your server is supposed to return a 'Location:' header which points to the new location. In practice, the way this is implemented varies; some servers provide the full URL (netloc and path), some just provide the new path and expect the browser to look for that path on the original netloc. It sounds like your rewrite rule is stripping the path.
An easy way to see what the returned Location header is, in the python shell:
>>> import httplib
>>> conn = httplib.HTTPConnection('exemple.oursite.com')
>>> conn.request('HEAD', '/')
>>> res = conn.getresponse()
>>> print res.getheader('location')
I'm afraid I don't know enough about mod_rewrite to tell you how to do the rewrite rule correctly, but this should give you an idea of what your server is actually telling clients to do.
The search bots don't care about hash tags. And if you are using them for some kind of flash or AJAX calls, you have more serious problems than your 301 redirects don't work. Because unless you have the content in an alternate form, the search engines are not indexing your site and you are definitely suffering as far as SEO goes.
I registered my account so I can't edit.
zombat : I'm sorry I made a mistake in my comment. The link to our video is exemple.oursite.com/#video_id=233. In this case, my rewrite rule in Apache doesn't work.
Nick Berardi: We changed the way our links work. We don't use # anymore, only for backward compatibility

Resources