Forum Moderators: phranque
I have a web site as below
http://www.example.com/about.htm
http://www.example.com/contact.htm
but I want to show it like--
http://www.example.com/about
http://www.example.com/contact
I have visited this forum and seen some code like below is using as .htaccess file but it is not working.
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(. )\.htm\ HTTP/
rewriterule ^(. )\.htm$ /$1 [R=301,L]
Please give me some suggestion that I have been searching it since the last two days but yet not solved as I don't know so much about this programming.
[rankinglabs.com...]
But it does look like it does what you're looking for.
Thanks for you reply and give me an advice.
But buddy I have change some codes in my site and it is now working! :D
the code is as below
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_fileNAME} !-d
RewriteCond %{REQUEST_fileNAME} !-f
rewriterule ^(([^/]+/)*[^./]+)/?$ /$1.htm [L]
Your newest rule above internally rewrites extensionless URL requests to filepaths with the .htm file extension.
The rule you posted in your first post was probably intended to redirect requested URLs with .htm extensions to URLs without file extensions to 'clean up' search engine listings that show URls with .htm extensions, and to recover the traffic and PageRank of the old links.
It may take some further tweaking to work properly on your server, but the whole solution is:
1) Change links on your pages to remove ".htm"
2) Rewrite extensionless URL requests to files with .htm extensions (if they exist)
3) Redirect requests for old .htm URLs to new extensionless URLs (if the .htm file exists)
4) Redirect to remove trailing slashes from extensionless URL requests
RewriteEngine on
RewriteBase /
#
# Redirect direct client request for old URL with .htm extension
# to new extensionless URL if the .htm file exists
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/\ ]+/)*[^.\ ]+\.htm\ HTTP/
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(([^/]+/)*[^.]+)\.htm$ http://www.example.com/$1 [R=301,L]
#
# Redirect any request for a URL with a trailing slash to extensionless URL
# without a trailing slash unless it is a request for an existing directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ http://www.example.com/$1 [R=301,L]
#
# Internally rewrite extensionless URL request
# to .htm file if the .htm file exists
RewriteCond %{REQUEST_FILENAME}.htm -f
RewriteRule ^(([^/]+/)*[^./]+)$ /$1.htm [L]
Jim
Thanks to you for the great explanation.
Jim, as I am using the below code in .htaccess and the site's response is perfect as I wanted so if there is any problem or anything more to do please suggest me. the site is <snip> and the code is
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_fileNAME} !-d
RewriteCond %{REQUEST_fileNAME} !-f
rewriterule ^(([^/]+/)*[^./]+)/?$ /$1.htm [L]
[edited by: jdMorgan at 5:04 am (utc) on July 21, 2009]
[edit reason] No URLs, please. See Terms of Serice. [/edit]