RewriteRule ^([^/]+)_([^/]+) /areas/$1_$2.html [NC]
<div> <p> Blah </p> </div>
<div>...</div>
RewriteRule ^([^/]+)_([^/]+) /area/$1_$2.html [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule Pattern Substitution [OptionalFlags]
RewriteRule ^(.*)\.html index.php?q=$1 [L,QSA] RewriteRule ^(.*)\.html index.php?q=$1 [L,QSA]
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
RewriteRule ^([^/.]+)$ /test/$1 [NC]
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} ^domain\.com [NC]
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
RewriteRule ^([^/.]+)$ /test/$1.html [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]<?php
// should recognize shortened urls as valid if they are in specific directories that are in the top level - ie. only folder/FILE.html
// this way you can use folders somewhat like categories
// however, if you want the extension to be part of the shortened url, then take out anything to do with $extensions
// meaning if you want to shorten the url to www.domain.com/FILE.html, instead of www.domain.com/FILE
// this also doesn't work well with wayfinder because wayfinder will put in the 'folder' and the extension
// but the files can still be accessed through folder/FILE.html,
// just be careful because the search engines will see it as duplicate content
// will NOT work for folder/subfolder/FILE.html
$alias = null;
$alias_check = array();
$folder_id = array(5);// the resource id(s) of the folder(s) that can be omitted from the url
$extensions = array('.html', '/');// the extensions to check
if($modx->_systemConfig['friendly_alias_urls'] == 1)
{
if ($modx->event->name == 'OnWebPageInit')
{
foreach($folder_id as $key => $value)
{
$folder_id = $value;
$folder = $modx->getObject('modResource', array('id' => $folder_id) );
$alias_folder = $folder->get('alias') .'/';
// gets the FILE - the url the user is trying to request
$alias = $modx->request->getResourceIdentifier('alias');
foreach($extensions as $key => $value)
{
$alias_ext = $value;
// builds the url to check
$alias_check[] = $alias_folder . $alias . $alias_ext;
}
}
}
}
if($alias)
{
foreach($alias_check as $key => $value)
{
$alias_path = $value;
$holder = $modx->aliasMap;
// if 'folder/FILE.html' IS in the alias map or 'site tree'
if( isset( $holder[ $alias_path ] ) )
{
// get the id of folder/FILE.html
$actualDocId = $holder[ $alias_path ];
// this will allow people to enter www.domain.com/FILE
// and instead of being a 404 error
// it will load www.domain.com/folder/FILE.html
// but show as www.domain.com/FILE
// load the resource, but leave url as www.domain.com/FILE
$modx->sendForward($actualDocId);
exit();
}
// check as case-insensitive, just in case user didn't capitilize url correctly
$alias_path = strtolower( $alias_path );
$holder = array_change_key_case( $holder );
// if 'folder/file.html' IS in the alias map or 'site tree'
// then send error 404 because they didn't type url correctly - ie. case-sensative
if( isset( $holder[ $alias_path ] ) )
{
// creates the http://www.domain.com/
$holder_2 = $modx->placeholders;
$base_url = $holder_2['site_url'];
// get the id of folder/FILE.html
$actualDocId = $holder[ $alias_path ];
// get the resource, and then build the shortened url to forward to
$file = $modx->getObject('modResource', array('id' => $actualDocId) );
$url = $base_url . $file->get('alias');
$modx->sendRedirect($url, 0, '', 'HTTP/1.0 301 Moved Permanently');
exit();
}
}
}