-2

I am not sure if you would do this in the .htacess file but,

I have a page www.website.com/page2.html

How would I make the URL look like www.website.com/page2

Nhan
  • 3,595
  • 6
  • 30
  • 38
Enrique Avina
  • 973
  • 7
  • 20

2 Answers2

1

With .htaccess under apache you can do the redirect like this:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.html$ /$1 [L,R=301] 

As for removing of .html from the url, simply link to the page without .html

<a href="http://www.website.com/page2">page</a>
Mirza Obaid
  • 1,707
  • 3
  • 23
  • 35
1

This should work for you:

example.com/page will display the contents of example.com/page.html

<IfModule mod_rewrite.c>
    Options +FollowSymLinks
    RewriteEngine On
    RewriteBase /

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}.html -f
    RewriteRule ^(.+)$ $1.html [L,QSA]
</IfModule>

301 from example.com/page.html to example.com/page

<IfModule mod_rewrite.c>
    Options +FollowSymLinks
    RewriteEngine On
    RewriteBase /

    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.html\ HTTP/
    RewriteRule ^(.*)\.html$ /$1 [R=301,L]
</IfModule>
Editor
  • 622
  • 1
  • 11
  • 24