|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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! |
|
#2
|
|||
|
|||
|
Try this one:
PHP Code:
Quote:
|
|
#3
|
|||
|
|||
|
Thanks for your reply! But is there maybe also an alternative via the .htaccess-file...?
|
|
#4
|
|||
|
|||
|
Automatically adding .html to urls (.htaccess)
Quote:
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. |
![]() |
| Viewing: SEO Chat Forums > Other > SEO Scripts > Automatically adding .html to urls (.htaccess) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|