How to configure routing in Apache?

How to hide my .html files, for example, when I go to www.mysite.com, it redirects to www.mysite.com/index.html, but it hides the /\index.html file, so it remains as www. mysite.com, but actually www.mysite.com/index.html. I don’t know how to explain, but if you understand me, can you help, thanks.

+4
source share
5 answers

Try this, here we set the index of the directory, so we do not need to specify index.html in every call. and rewriting every html without extension.

DirectoryIndex index.html

RewriteEngine on
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^([\w-]+)$ $1.html [L]
0
source

.htaccess - ASCII, , TextMate. .

RewriteRule ^([^\.]+)$ $1.html [NC,L]

- .php,.html,.htm .htaccess

+3

, .htaccess.

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

.html URL-, . , URL- www.mysite.com/contact.html, , , www.mysite.com/contact.

+3

apache. .

. , . contact.html index.html. .

www.mysite.com/contact ( www.mysite.com/contact/index.html).

0

URL- . JavaScript HTML :

history.replaceState('data to be passed', 'Title of the page', 'theNameWithoutTheHTML');

.js , script :

history.replaceState('data to be passed', 'Title of the page', location.pathname.slice(0, -5)); //This will replace it with the same path, removing the ".html" at the end (take care if the extension is different sized)

In this case, you are redirected to the .html file, this should not be a problem when the user reloads the page (since it will try to load the page without .html).

0
source

Source: https://habr.com/ru/post/1656684/


All Articles