You're right, folder structure can help out a bit, but in the same time, you do not really want a web site with a thousand folder with just one
page in them.
Folders can be good to help out categorizing content, for both bots and human, but you need content to categorize, at least some, and better if you continue to add articles.
About redirections, that's the principle, but, you cannot really add thousand of rewriterules in your .htaccess.
For few it's ok to add things like :
- Code: Select all
RewriteRule ^page_title\.html$ /cat_folder/page_title.xml [L, R=301]
at the very end of your .htaccess for example.
But if you really have many it's handier to deal with a script to redirect them.
The principle would be to redirect any html file that seems to first not exist top a script that will either redirect, if the file does exist but went moved or a 404 when it really does not exist.
At the very end of your .htaccess :
- Code: Select all
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([a-z0-9_-]+)\.html$ /redir.php?uri=$1 [QSA,L]
and redir.php would be something like :
- Code: Select all
<?php
// Config
$url = "http://www.example.com/"; // Your domain's root url, with trailing slash
// The pages array, with old vs new titles, notice the key does not use .html, but the value does.
$pages_array = array( 'page_title1' => 'folder1/page_title1.html,
'page_title2' => 'folder2/page_title3.html,
);
$uri = (isset($_GET['uri'])) ? trim(htmlspecialchars(strtolower(($_GET['uri']))) : '';
if ( !empty($uri) && !empty($pages_array[$uri]) ) { // the page exists
$url .= trim($pages_array[$uri]);
header("HTTP/1.1 301 Moved Permanently", FALSE , 301);
header("Location:" . $url);
exit();
} else { // it's a 404
$message = "the message to be displayed for 404s, can have links to your index in it and html";
header("HTTP/1.1 404 Not Found");
header ('Content-Type: text/html');
echo '<html><head><title>' . $header_msg . '</title><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"></head><body><br/><pre>' . $message . '</pre></body></html>';
exit();
}
?>
This is handy as well because you can take the occasion to rename some files as well as to move them this way.
You just need to populate the $pages_array :
- Code: Select all
$pages_array = array( 'page_title1' => 'folder1/page_title1.html',
'page_title2' => 'folder2/page_title3.html',
);
As you can see with this, page_title
1.html => folder1/page_title
1.html and page_title
2.html => folder2/page_title
3.html
The 404 is here important because this script will handle all possible .html files at the server root level that does not exist, the one you'd like to redirect (since they have moved, they do not exist at the root level) and the real 404s, so you want to output 404 for the real 404 for SE's to continue to find their way in your site properly.
