N
N
ni4evova2021-03-09 19:35:02
htaccess
ni4evova, 2021-03-09 19:35:02

Why don't internal links on the site work in Open Server? .htaccess?

Hi guys! They asked me to make changes to a simple site, essentially in HTML / CSS, but with PHP elements - so I installed Open Server for local work. Understood to the stage that the site opens.

But I click on an internal link, for example "Contacts" = 'contacts' - I get a 403 error. In the Apache debug log I see the following:

applying pattern '.*\\.php$' to uri 'contacts', referer: http://stretto.loc/
RewriteCond: input='D:/OpenServer/domains/stretto.loc/public_html/contacts.php' pattern='-f' => matched, referer: http://stretto.loc/
rewrite 'contacts' -> 'D:/OpenServer/domains/stretto.loc/public_html/contacts.php', referer: http://stretto.loc/
add per-dir prefix: D:/OpenServer/domains/stretto.loc/public_html/contacts.php -> D:/OpenServer/domains/stretto.loc/public_html/D:/OpenServer/domains/stretto.loc/public_html/contacts.php, referer: http://stretto.loc/
strip document_root prefix: D:/OpenServer/domains/stretto.loc/public_html/D:/OpenServer/domains/stretto.loc/public_html/contacts.php -> /D:/OpenServer/domains/stretto.loc/public_html/contacts.php, referer: http://stretto.loc/
internal redirect with /D:/OpenServer/domains/stretto.loc/public_html/contacts.php [INTERNAL REDIRECT], referer: http://stretto.loc/
(20023)The given path was above the root path: [client 127.0.0.1:62943] AH00127: Cannot map GET /contacts HTTP/1.1 to file, referer: http://stretto.loc/


From the last two lines, I understand that there seems to be an extra "/" at the beginning. And also lines 4 and 5 do something superfluous - first adding the path to the file once again, and then removing it, apparently leaving "/".

Here is the .htaccess:

adddefaultcharset utf-8

RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]


This syntax is a dark forest for me (and I installed Open Server for the first time) ...

What do I need to change in .htaccess or maybe in the server settings so that links are processed correctly?

Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2021-03-10
@ni4evova

You need to change REQUEST_FILENAME to REQUEST_URI in RewriteRule.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_URI}.php [QSA,L]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question