Hide .html in url - html

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]

Related

How to redirect website.com/ and website.com/index.php to another page with htaccess

I can redirect website.com/index.php to website.com/home but I can't find a way to redirect website.com to website.com/home
I have tried RewriteRule ^/$ /home [R=301] but it does nothing.
A single rule can handle both redirects:
RewriteRule ^/?(index\.php)?$ /home [NC,L,R=301]
Try this
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?website\.com$ [NC]
RewriteRule .* http://www.website.com/home [R=301,L]
This rule redirects www.website.com to www.website.com/home
Or add this to your .htaccess
RewriteRule ^/?$ /home [R=301,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.!

How to redirect html extension using htaccess?

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]

htaccess to redirect main domain

I have a htaccess that redirects my main domain "www.main.com" to "www.main.com/DBS2010".
The htaccess works but my url changes to "www.main.com/DBS2010" can I make the url stay as "www.main.com"?
htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?main.com$
RewriteRule ^(/)?$ DBS2010 [L]
You can try this code for that:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?main\.com$ [NC]
RewriteRule ^$ DBS2010 [L]
This will not change URL in browser to `/DBS2010'.