SEO Scripts
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   SEO Chat ForumsOtherSEO Scripts

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread SEO Chat Forums Sponsor:
  #1  
Old December 13th, 2007, 05:48 AM
MrMiguel MrMiguel is offline
Contributing User
SEO Chat Newbie (0 - 499 posts)
 
Join Date: Jul 2007
Posts: 63 MrMiguel User rank is Private First Class (20 - 50 Reputation Level)MrMiguel User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Day 10 h 40 m 3 sec
Reputation Power: 2
Automatically adding .html to urls (.htaccess)

I would like to have the urls visitors enter with are automatically adjusted (via .htaccess) such that if a visitor (or search engine bot) enters my website at any url of this type:

http://www.mywebsite.com/page
http://www.mywebsite.com/page.htm
www.mywebsite.com/page
www.mywebsite.com/page.htm
mywebsite.com/page
of mywebsite.com/page.htm

that they then automatically get send to: http://www.mywebsite.com/page.html. This should also hold for all other pages of my website, EXCEPT for the homepage;

http://www.mywebsite.com
http://www.mywebsite.com/index
http://www.mywebsite.com/index.htm
http://www.mywebsite.com/index.html

should all automatically be changed into:

http://www.mywebsite.com

Currently my .htaccess-file looks like this:

Code:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.mywebsite.com$ [NC]
RewriteRule ^(.*)$ http://www.mywebsite.com/$1 [L,R=301]

Such that adding the "http://www." part is currently already working.

What should I add now such that the ".html"-part is automatically added as well and such that the above mentioned exceptions for the homepage work?

Thanks A LOT in advance for your help here!!

Last edited by pro_seo : December 13th, 2007 at 06:12 AM. Reason: Fixed the code tag!

Reply With Quote
  #2  
Old December 13th, 2007, 11:36 AM
lordspace lordspace is offline
Contributing User
SEO Chat Newbie (0 - 499 posts)
 
Join Date: May 2006
Location: Canada
Posts: 50 lordspace User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 41 m 42 sec
Reputation Power: 3
Send a message via ICQ to lordspace
Try this one:

PHP Code:
<?php

/*
 For requests without an extension e.g. 'http://domain.com/index' automatically redirect (301) to an existing file with 
 extension specified by $ext variable.
 
 author: Svetoslav Marinov aka Lordspace
 License: LGPL
 (c) 2007
*/

$req $_SERVER['REQUEST_URI'];
$ext '.htm';

// if the requested file does not contain an extension and is a file then add .html extenstion and make redirect.
if (preg_match('#(.*/[^\.]+)$#'$req$matches)) {
    
    
// Just in case.
    
$matches[1] = str_replace('..'''$matches[1]);
    
    
// add '.' to search the file from the current folder
    
$location '.' $matches[1] . $ext;
    
    if (
is_file($location)) {
        
header((php_sapi_name() == 'cgi' 'Status:' 'HTTP/1.1') . ' 301 Moved Permanently'); 
        
header('Location: ' $location);
        exit;
    }
}
 
?>



Quote:
Originally Posted by MrMiguel
I would like to have the urls visitors enter with are automatically adjusted (via .htaccess) such that if a visitor (or search engine bot) enters my website at any url of this type:

http://www.mywebsite.com/page
http://www.mywebsite.com/page.htm
www.mywebsite.com/page
www.mywebsite.com/page.htm
mywebsite.com/page
of mywebsite.com/page.htm

that they then automatically get send to: http://www.mywebsite.com/page.html. This should also hold for all other pages of my website, EXCEPT for the homepage;

http://www.mywebsite.com
http://www.mywebsite.com/index
http://www.mywebsite.com/index.htm
http://www.mywebsite.com/index.html

should all automatically be changed into:

http://www.mywebsite.com

Currently my .htaccess-file looks like this:

Code:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.mywebsite.com$ [NC]
RewriteRule ^(.*)$ http://www.mywebsite.com/$1 [L,R=301]

Such that adding the "http://www." part is currently already working.

What should I add now such that the ".html"-part is automatically added as well and such that the above mentioned exceptions for the homepage work?

Thanks A LOT in advance for your help here!!

Reply With Quote
  #3  
Old December 13th, 2007, 11:40 AM
MrMiguel MrMiguel is offline
Contributing User
SEO Chat Newbie (0 - 499 posts)
 
Join Date: Jul 2007
Posts: 63 MrMiguel User rank is Private First Class (20 - 50 Reputation Level)MrMiguel User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Day 10 h 40 m 3 sec
Reputation Power: 2
Thanks for your reply! But is there maybe also an alternative via the .htaccess-file...?

Reply With Quote
  #4  
Old January 17th, 2008, 09:38 AM
forge forge is offline
Registered User
SEO Chat Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Posts: 1 forge User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 13 sec
Reputation Power: 0
Automatically adding .html to urls (.htaccess)

Quote:
Originally Posted by MrMiguel
I would like to have the urls visitors enter with are automatically adjusted (via .htaccess) such that if a visitor (or search engine bot) enters my website at any url of this type:

http://www.mywebsite.com/page
http://www.mywebsite.com/page.htm
www.mywebsite.com/page
www.mywebsite.com/page.htm
mywebsite.com/page
of mywebsite.com/page.htm

that they then automatically get send to: http://www.mywebsite.com/page.html. This should also hold for all other pages of my website, EXCEPT for the homepage;

http://www.mywebsite.com
http://www.mywebsite.com/index
http://www.mywebsite.com/index.htm
http://www.mywebsite.com/index.html

should all automatically be changed into:

http://www.mywebsite.com

Currently my .htaccess-file looks like this:

Code:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.mywebsite.com$ [NC]
RewriteRule ^(.*)$ http://www.mywebsite.com/$1 [L,R=301]

Such that adding the "http://www." part is currently already working.

What should I add now such that the ".html"-part is automatically added as well and such that the above mentioned exceptions for the homepage work?

Thanks A LOT in advance for your help here!!



Hi

You are most of the way there. If you are not linking to an external site then you are rewriting URLs relative to your document root. Here is what you need instead of the above which looks like some sort of permanent redirect.

Code:
RewriteEngine On
RewriteRule (.*) /page.html
RewriteRule index.html /


The first rule says anything goes to page.html and the second overrides it for index.html

If you need it to be recursive throughout sub-folders you'll need to add the RewriteCondition above however I find it better if it starts with something. Example:
Code:
RewriteEngine On
RewriteRule digital-camera-brands-(.*).htm /page.php?brand=$1


So for example the page digital-camera-brands-Kodac.htm would be taken from page.php?brand=Kodak

Thus you could have all your brands in a database and generate SE friendly urls for dragging them out. Moreover you can generate a complete page by adding a brand name to the database.

Hope that helps :-)

Last edited by forge : January 17th, 2008 at 09:42 AM.

Reply With Quote
Reply

Viewing: SEO Chat ForumsOtherSEO Scripts > Automatically adding .html to urls (.htaccess)


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT