How to redirect html extension using htaccess? - html

At the moment, both of these links show the same page:
http://www.example.com/podcast/episode.html
http://www.example.com/podcast/episode
What I want to do is redirect all the html-type links to the non-html links.
I know this might seem simple to do with htaccess, but it's not working for me.
Here's my htaccess code so far:
RewriteEngine On
RewriteBase /
#removing trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ $1 [R=301,L]
#non www to www
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
#shtml
AddType text/html .html
AddHandler server-parsed .html
#html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.html [NC,L]
#index redirect
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/
RewriteRule ^index\.html$ http://example.com/ [R=301,L]

RewriteCond %{THE_REQUEST} \.html
RewriteRule ^(.*)\.html$ /$1 [R=301,L]

Related

How to 301 redirect from map

I made a website where I made an English version as well. The English version map is in /en.
The normal site of mine, redirects with this code:
RewriteCond %{HTTP_HOST} ^www.mysite.nl$ [NC]
RewriteRule ^(.*)$ http://mysite.nl/$1 [R=301,L]
The English version is in the /en map so I thought this would work, but it doesn't.
RewriteCond %{HTTP_HOST} ^www.mysite.nl/en$ [NC]
RewriteRule ^(.*)$ http://mysite.nl/en/$1 [R=301,L]
Does someone know how to 301 redirect when the site is in a folder?
With your shown samples, please try following htaccess Rules. Please make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
##Rules for putting en in uris.
RewriteCond %{HTTP_HOST} ^www\.mysite\.nl$ [NC]
RewriteCond %{REQUEST_URI} !^/en [NC]
RewriteRule ^(.*)/?$ http://mysite.nl/en/$1 [R=301,L]
##Other rules for redirection.
RewriteCond %{HTTP_HOST} ^www\.mysite\.nl$ [NC]
RewriteRule ^(.*)/?$ http://mysite.nl/$1 [R=301,L]

I attempted to remove the .html extension from my pages and now when clicked, navigation goes to another site

*This question is unique because I do not need to remove the .html from the file extensions; I need to have internal links function correctly.
My site is http://purplerosecare.com and I tried creating a .htaccess page with the suggested copy/paste from the SO page: How to remove .html from URL
The code I used is below:
RewriteEngine on
RewriteBase /
RewriteCond %{http://www.proofers.co.uk/new} !(\.[^./]+)$
RewriteCond %{REQUEST_fileNAME} !-d
RewriteCond %{REQUEST_fileNAME} !-f
RewriteRule (.*) /$1.html [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+)\.html\ HTTP
RewriteRule ^([^.]+)\.html$ http://www.proofers.co.uk/new/$1 [R=301,L]
(The code & .htaccess have both been removed)
The problem I'm facing is whenever I click on a link in the navigation it sends me to http://www.proofers.co.uk/new/. How can I get the site functional again?
Try this in your Root/.htaccess file
#Remove html extensions from files
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.html [NC]
RewriteRule ^ %1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*?)/?$ $1.html [L]

Redirection through htaccess from non html to .html extension?

i want to add .html to my html files automatically using htaccess.
As we can remove .html very easily but i want to know can i add .html to a non html file that is located with my website.
for example this is my domain
www.abc.com/name.html
but when i am accessing
www.abc.com/name
It is showing me the same page but not automatically adding the .html extension.
So i want that if i try to open
www.abc.com/name then it automatically shows me www.abc.com/name.html
How to achieve this.
Thanks
You can use this rule:
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://pcsmartcare.com%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+?)/?$ /$1.html [L,R=301]
RewriteCond %{THE_REQUEST} /index\.html?\s [NC]
RewriteRule ^(.*)index\.html?$ /$1 [R=301,L,NC]

how to use .htaccess file in our HTML website? for remove page extention from website

I have a HTML website and I want to remove pages extension (.html) from my website. I've used .htaccess file but I don't know how to use .htaccess file in my website's page.
Anybody please help me.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
No need to add code in any page.Create .htacess file with above content & add file to the root folder of your site(for example, /home/domains/domain.com/htdocs/)
RewriteEngine On
RewriteCond %{THE_REQUEST} ^GET\ /([^.\ ]+\.)+html(\?[^\ ]*)?\ HTTP
RewriteRule ^(.+)\.html$ http://www.example.com/$1 [R=301,L]
RewriteRule ^([^/]+/)*index/?$ http://www.example.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ http://www.example.com/$1 [R=301,L]
RewriteCond $1 !^([^.]+\.)+([a-z0-9]+)$ [NC]
RewriteCond %{REQUEST_FILENAME}.html-f
RewriteRule ^(.*[^/])$ /$1.html[L]
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteRule (.*) http://www.example/$1 [R=301,L]
Change whole content of .htaccess with above one ,I hope above will helpful.!

Hide .html in url

I want to hide .html from url, example www.site.com/videos.html to www.site.com/videos. I looked for similar questions here but with no result.
This is my .htaccess file:
RewriteEngine On
RewriteRule ^index.html$ index.php
RewriteRule ^browse-(.*)-videos.html$ category.php?cat=$1
RewriteRule ^browse-(.*)-videos-([0-9]+)-(.*).html$ category.php?cat=$1&page=$2&sortby=$3
RewriteRule ^register.html$ register.php
RewriteRule ^contact_us.html$ contact_us.php
RewriteRule ^edit_profile.html$ edit_profile.php
RewriteRule ^suggest.html$ suggest.php
RewriteRule ^upload.html$ upload.php
RewriteRule ^upload_avatar.html$ upload_avatar.php
RewriteRule ^suggest.html$ suggest.php
RewriteRule ^favorites.html(.*)$ favorites.php$1
RewriteRule ^login.html(.*)$ login.php$1
RewriteRule ^newvideos(.*)$ newvideos.php$1
RewriteRule ^topvideos.html(.*)$ topvideos.php$1
RewriteRule ^profile.html(.*)$ profile.php$1
RewriteRule ^favorites.html(.*)$ favorites.php$1
RewriteRule ^playlist/(.*)$ myfavorites.php?u=$1
RewriteRule ^memberlist.html(.*)$ memberlist.php$1
RewriteRule ^articles/read-(.*)_([0-9]+).html$ article_read.php?a=$2
RewriteRule ^articles/index-([0-9]+).html$ article.php?page=$1
RewriteRule ^articles/browse-(.*)-([0-9]+).html$ article.php?c=$1&page=$2
RewriteRule ^articles/tag/([^/]+)/page-([0-9]+)(/)?$ article.php?tag=$1&page=$2
RewriteRule ^articles/tag/([^/]+)(/)?$ article.php?tag=$1&page=1
RewriteRule ^articles/popular-([0-9]+).html$ article.php?show=popular&page=$1
RewriteRule ^articles(\/|.html)?$ article.php
RewriteRule ^article(\/|.html)?$ article.php
RewriteRule ^pages/(.*)\.html$ page.php?name=$1
RewriteRule ^tags/([^/]+)/$ tag.php?t=$1&page=1
RewriteRule ^tags/([^/]+)/page-([0-9]+)(/)?$ tag.php?t=$1&page=$2
RewriteRule ^([^/]*)-video_(.*).html$ watch.php?vid=$2
RewriteRule ^fpembed-(.*).swf$ fpembed.php?vid=$1
RewriteRule ^rss.xml$ rss.php [L]</code></pre>
If you just want to redirect the client from videos.html to videos
RewriteRule ^/?videos.html$ /videos
this requires, that /videos is a valid URL.
Try this:
RewriteRule ^([^.]+)$ $1.html [NC,L]