E
E
egosnob2019-08-01 13:34:18
htaccess
egosnob, 2019-08-01 13:34:18

How to remove .html endings from URL in .htaccess?

fix htaccess. I want to ensure that all page addresses end with a slash, instead of .html, by analogy with categories. I figured out that these are the last lines that answer, but when you try to make any changes - a white page

.htaccess

AddDefaultCharset utf-8
<Files ".htaccess">
deny from all
</Files>
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
ErrorDocument 404 /404.html
ErrorDocument 403 /403.html
#
RewriteRule ^index.html$ /$1 [L,R=301]
# admin
RewriteRule ^admin/$ admin/index.php
RewriteRule ^admin.html$ admin/index.php
RewriteRule ^admin$ admin/index.php
# captcha
RewriteRule ^captcha.php$ mycode/captcha.php
# photo
RewriteRule ^photo-cat-([-a-zA-Z0-9_]*)?-([0-9]*)?.html$ index.php?whatpage=photo&cat=$1&page=$2
RewriteRule ^photo-cat-([-a-zA-Z0-9_]*).html? index.php?whatpage=photo&cat=$1
RewriteRule ^photo-([0-9]*).html? index.php?whatpage=photo&page=$1
# news
RewriteRule ^news/index.php$ /news/ [QSA,R]
RewriteRule ^news/$ index.php?whatpage=news
RewriteRule ^news.html$ /news/ [QSA,R]
RewriteRule ^news/page([0-9]*)?.html$ index.php?whatpage=news&newspage=$1
RewriteRule ^news/([-a-zA-Z0-9_]*)/?index.php$ /news/$1/ [QSA,R]
RewriteRule ^news/([-a-zA-Z0-9_]*)/?page([0-9]*)?.html$ index.php?whatpage=news&catnews=$1&newspage=$2
RewriteRule ^news/([-a-zA-Z0-9_]*)?.html$ index.php?whatpage=news&view=$1
RewriteRule ^news/([-a-zA-Z0-9_]*)/?$ index.php?whatpage=news&catnews=$1
RewriteRule ^news/([-a-zA-Z0-9_]*)/?([-a-zA-Z0-9_]*)?.html$ index.php?whatpage=news&catnews=$1&view=$2
# guestbook
RewriteRule ^guestbook-start-([0-9]*).html?$ index.php?whatpage=guestbook&start=$1
RewriteRule ^guestbook-post-([0-9]*).html?$ index.php?whatpage=guestbook&id=$1
# pages
RewriteRule ^([-a-zA-Z0-9_]*)?.html$ index.php?whatpage=$1
RewriteRule ^([-a-zA-Z0-9_]*)/?([-a-zA-Z0-9_]*)/?spage-([0-9]*)?.html$ index.php?catpage=$1&subcatpage=$2&spage=$3
RewriteRule ^([-a-zA-Z0-9_]*)/?([-a-zA-Z0-9_]*)?.html$ index.php?catpage=$1&whatpage=$2
RewriteRule ^([-a-zA-Z0-9_]*)/?$ index.php?catpage=$1
RewriteRule ^([-a-zA-Z0-9_]*)/?([-a-zA-Z0-9_]*)/?([-a-zA-Z0-9_]*)?.html$ index.php?catpage=$1&subcatpage=$2&whatpage=$3
RewriteRule ^([-a-zA-Z0-9_]*)/?([-a-zA-Z0-9_]*)/?$ index.php?catpage=$1&subcatpage=$2

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
slava kk, 2019-08-01
@slavchickalpha

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)$ $1.html [NC,L]

K
kirill_andreev, 2019-12-24
@kirill_andreev

For this you need a special formula. I know that it is not so easy to find it, few people write about it on the Internet. But I know exactly where you can get the answer to your question about html . Just go here and ask. Experienced programmers sit on the site, who will give you a clear and intelligible answer without any problems. The main thing is to do everything as they wrote.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question