"Nel" <ne***@ne14.co.NOSPAMuk> wrote in
news:Lv*********************@stones.force9.net:
"Edward Alfert" <ea*****@rootmode.com> wrote in message
news:Xn********************************@130.133.1. 4... "Nel" <ne***@ne14.co.NOSPAMuk> wrote in news:DwGxc.12894$NK4.1841718
@stones.force9.net:
> Just looking for some general advice on modifying the URL for php.
>
> I am using .htaccess to allow a web site to translate example.html
> to index.php?content=example
> (below)
>
> ErrorDocument 404 http://www.example.com
> RewriteEngine on
> RewriteRule ^/?(.*).html$ /index.php?content=$1 [L]
>
> Is there any downside to using this method. I just want to know
before I > roll it out over several other sites.
>
> Nel.
>
Nel,
I use something similar.
1) I redirect alias domains and domains without www. in front to my
main domain using a 301 redirect which is what Google likes in order
to maintain pagerank.
2) I test to make sure the page being requested is not a file or
directory that exists. If it exists, then retrive the existing page.
This is nice in case you want to have a pages that are not part of
your content management system.
3) I don't just redirect pages with .html extensions. I redirect
everything into content management system and then the cms parses the
requested page and strips extensions, trailing slashes, etc.
Options +SymlinksIfOwnerMatch
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.rootmode\.com
RewriteRule ^(.*)$ http://www\.rootmode\.com/$1 [R=
301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ $1 [L]
RewriteCond %{REQUEST_URI} !^/index\.php
RewriteRule ^(.*)$ /index.php?page=$1 [L]
--
Edward Alfert
http://www.rootmode.com/
Multiple Domain Hosting and Reseller Hosting Plans
Coupon Code (Recurring $5/month Discount): newsgroup
One of the reasons I am using .html is to give the site the look and
feel of a static html web site. I was under the impression, that with
some exceptions (like Google) search engines list the pages better
than index.php?content=example.
2) I test to make sure the page being requested is not a file or
directory that exists. If it exists, then retrive the existing page.
This is nice in case you want to have a pages that are not part of
your content management system.
If I need a stand alone page, it will probably have some php
requirement, so I would probably just call existing pages example.php.
I'm not likely to ever have static html files that could not be moved
over to content management.
Thanks for the detailed feedback. I had a look at your web site and
see what you mean. It works very well! :-)
Nel.
Nel,
The url is not rewritten to
http://www.domain.tld/index.php?
content=example... it stays
http://www.domain.tld/example so search
engines do not see that it is a dynamic site. They see a static url.
The site you looked at uses a differnt but similar technique that has
some drawbacks (like not being able to handle trailing slashes "/").
The code I listed is for the redesign I'm currently working on.
The code above is only the .htaccess portion, see the index.php page
that does other manipulation (not 100% done yet).
<?php
//========================================
//RootMode CMS -
http://cms.rootmode.com/
//----------------------------------------
/*****************************************
Place the following in .htaccess in root directory
Make sure to modify domain in first RewriteCond and RewriteRule
******************************************
Options +SymlinksIfOwnerMatch
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.rootmode\.net
RewriteRule ^(.*)$ http://www\.rootmode\.net/$1 [R=
301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ $1 [L]
RewriteCond %{REQUEST_URI} !^/index\.php
RewriteRule ^(.*)$ /index.php?page=$1 [L]
*****************************************/
//========================================
//Set system/site specific variables
//----------------------------------------
$domain = $_SERVER["HTTP_HOST"]; //Can also set
manually to "www.domain.tld"
$path = "/var/www/html/"; //Absolute path is
preferred but relative will work
$dir_content = "content/";
$ext = ".php"; //Extension of
physical content files. Will not be displayed in address bar of
browser.
$page_default = "multiple-domain-hosting"; //No extension
$redirect_default = true; //true or false.
Useful for search engine optimization if set to true along with a
descriptive $page_default.
$page_404 = "sitemap"; //No extension
$dir_template = "template/";
$page_header = "header.php"; //Extension
required
$page_footer = "footer.php"; //Extension
required
$debug = true; //true or false
//========================================
//DO NOT MODIFY BELOW THIS LINE
//----------------------------------------
//========================================
//Send email if referred is a search engine
//----------------------------------------
//========================================
//Read requested page from mod_rewrite rule in .htaccess
//----------------------------------------
$page_content = $_REQUEST["page"];
if ($debug) { echo "(Test=User Requested Page):
page_content=".$page_content."<br />"; };
//========================================
//If no page was specified, retrieve default page
//----------------------------------------
if ((!$page_content) && ($redirect_default)) {
$page_redirect = $page_default;};
if ($debug) { echo "(Test=Redirect Default):
page_redirect=".$page_redirect."<br />"; };
if (!$page_content) { $page_content = $page_default; };
if ($debug) { echo "(Test=Default Page):
page_content=".$page_content."<br />"; };
//========================================
//If exists, remove trailing "/"
//Fix for search engines that append a "/" if the file being
requested does not have an extension
//Do not redirect to non-slash version because it might create a
loop
//----------------------------------------
if (substr($page_content,-1,1) == "/") { $page_content =
substr($page_content,0,-1); };
if ($debug) { echo "(Test=Trailing Slash):
page_content=".$page_content."<br />"; };
//========================================
//If exists, remove "." or ">"
//Fix for common problems of mangled links in emails
//----------------------------------------
$lastchar = substr($page_content, -1, 1);
if (($lastchar == '.') || ($lastchar == '>')) {
$page_redirect = substr($page_content, 0, -1); $page_content =
$page_redirect; };
if ($debug) { echo "(Test=Trailing . or >):
page_redirect=".$page_redirect."<br />"; };
//========================================
//If exists, remove extension
//----------------------------------------
//.htm, .php
if (substr($page_content,-4,1) == ".") {
$page_redirect = substr($page_content,0,-4); $page_content =
$page_redirect; };
//.html, .php3
if (substr($page_content,-5,1) == ".") {
$page_redirect = substr($page_content,0,-5); $page_content =
$page_redirect; };
//.shtml
if (substr($page_content,-6,1) == ".") {
$page_redirect = substr($page_content,0,-6); $page_content =
$page_redirect; };
if ($debug) { echo "(Test=Strip Extension): page_redirect=".
$page_redirect."<br />"; };
//========================================
//Force lower case for filename
//----------------------------------------
$page_content_lower = strtolower($page_content);
if ($page_content != $page_content_lower) { $page_redirect =
$page_content_lower; $page_content = $page_redirect; };
if ($debug) { echo "(Test=Lower Case):
page_redirect=".$page_redirect."<br />"; };
//========================================
//If requested page does not exist, then redirect to 404 page
//----------------------------------------
$file = $path.$dir_content.$page_content.$ext;
if ($debug) { echo "(Test=Physical Path): file=".
$file."<br />"; };
if (!file_exists($file)) { $page_redirect = $page_404; };
if ($debug) { echo "(Test=404): page_redirect=".
$page_redirect."<br />"; };
//========================================
//Determine which template (header and footer) to use
//----------------------------------------
if (!file_exists($path.$dir_content.$page_header)) {
$dir_header = $dir_content; } else { $dir_header = $dir_template; };
if ($debug) { echo "(Test=Header Path): dir_header=".
$dir_header."<br />"; };
if (!file_exists($path.$dir_content.$page_footer)) {
$dir_footer = $dir_content; } else { $dir_footer = $dir_template; };
if ($debug) { echo "(Test=Footer Path): dir_footer=".
$dir_footer."<br />"; };
//========================================
//Display content or do a 301 redirect to correct page
//----------------------------------------
if (!$page_redirect) {
include($path.$dir_header.$page_header);
include($path.$dir_content.$page_content.$ext);
include($path.$dir_footer.$page_footer);
} else {
header("Location: http://$domain/$page_redirect");
header("HTTP/1.0 301 Moved Permanently", true);
}
//========================================
//Helpful troubleshooting info
//----------------------------------------
if ($debug) { echo phpinfo(); };
//Uncomment next line to display phpinfo() even when not in
debug mode
//echo phpinfo();
?>
--
Edward Alfert
http://www.rootmode.com/
Multiple Domain Hosting and Reseller Hosting Plans
Coupon Code (Recurring $5/month Discount): newsgroup