Htaccess - the rewrite rule does not work when requesting a URL - this is a folder on my system

All requests to my site should be rewritten to index.php?page=blahwhere the blah page is requested (except for css, js, jp (e) g, gif and png files).

This is what my .htaccess file looks like:

RewriteEngine On
RewriteCond %{REQUEST_URI} !\.(?:css|js|jpe?g|gif|png)$ [NC]
RewriteRule ^(.*)$ index.php?page=$1 [L,QSA]

.htaccess is in this directory: localhost:8080/example/so when I go to localhost:8080/example/abcit is (internally) rewritten to localhost:8080/example/index.php?page=abc.

However, when I go to localhost:8080/example/res, I redirect to localhost:8080/example/res/?page=res. I found out that this only happens with directories; when I go to localhost:8080/example/core(also to a folder in my file system), I get redirected to localhost:8080/example/core/?page=corewhile it should be internally rewritten to localhost:8080/example/index.php?page=core, and the URL visible to the user should remainlocalhost:8080/example/core/

EDIT:

@w3dk, , . , :

: localhost:8080/example/index/a, localhost:8080/example/index.php?page=index.php/a, localhost:8080/example/index.php?page=index/a.

, , index , , localhost:8080/example/exampleFile/abc, localhost:8080/example/index.php?page=exampleFile.php/abc, .

2 :

  • index.php( )
  • example.php

Apache, , php , , , File.txt

+4
2

, , - mod_dir. (DirectorySlash On) mod_dir "" URL- . 301, . , URL, Location .

, . . localhost:8080/example/core/. mod_dir, "" URL- . ?

, - .htaccess:

DirectorySlash Off

, 301 mod_dir .

( ):
https://httpd.apache.org/docs/current/mod/mod_dir.html#directoryslash

+1

.htaccess . 1 URL-. http://domain.com/folder1/folder1.html. 1 .

RewriteEngine On
RewriteCond %{HTTP_HOST} domain.com$ [NC]
RewriteCond %{HTTP_HOST} !folder1
RewriteRule ^(.*)$ http://domain.com/folder1/$1 [R=301,L]
0

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


All Articles