V
V
Vladislav2021-01-19 04:31:06
htaccess
Vladislav, 2021-01-19 04:31:06

In the https:// version of the site, the .php extension is displayed in the address bar, in the http:// version there is no extension, how to remove the extension?

Hello!

http:// site.ru /page - displayed without the extension
https:// site.ru /page.php - the extension .php appears (when the redirect from http to https is enabled)
If you manually write https:// site.ru /page , then shows the extension
If you disable the redirect, then the http and https versions are displayed without the extension - as it should

. More: It was necessary to remove the file extension from the address bar of the http version of the site, then there was no ssl
certificate
php" to href="page". Added the following to the .htaccess file:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

Everything works well.

After some time, I connected an ssl certificate, added the code for 301 redirects to the very top of the .htaccess file:
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

The redirect works, but the file extension is now displayed.

The .htaccess file has only one more line of code at the very bottom, nothing else:
ErrorDocument 404 /404.php

I tried different ready-made combinations of code to "remove" the extension and redirect, but nothing works.
I don’t understand .htaccess at all, I didn’t find the answer on the Internet.

Please tell me how to solve my problem. Thank you for your attention!

Whole code
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

#ErrorDocument 404 /404.php

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladislav, 2021-01-19
@Leonard94

The following code, which I found on the Internet, helped me:

RewriteEngine on

RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]

RewriteCond %{SERVER_PORT} !^443
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ https://centeraudit.by%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP:X-SSL-Emu} !on
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

V
Vladimir, 2021-01-19
@HistoryART

I think it should look something like this:

RewriteRule .* https://%{SERVER_NAME}%{^(.*)$ $1.php} [R=301,L]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question