0

I read this question: How to set an index page in a subfolder. I want to make like this, I have these folders and files:

index.php
items/
items/index.php

and I want, when I search for "items/general", then items/index.php handles it, not index.php. I tried to make a .htacces file in /items/.htacces, with this:

RewriteEngine On

RewriteRule ^/?$ items/index.php [L]

BUT when I search for "items/general", it gives a 404 error, like this:

Not Found

The requested URL was not found on this server.

(and my items/index.php includes a code to send html to all request)

Why doesn't works it?

Nohab
  • 39
  • 6
  • Can you spell out what your RewriteRule above should do? – Markus AO Apr 08 '22 at 19:13
  • I want to forward the request for example "items/general" to items/index.php, not the index.php in the root. – Nohab Apr 08 '22 at 19:30
  • 1
    Yes I understood what you want. What I'm asking is, do you understand what your RewriteRule says there? And, how it's going to accomplish what you want? The regular expression reads: `^` start-of-subject `/` forward-slash `?` 0 or 1 of them `$` end-of-subject. What all would that match? (Hint: Empty _or_ one forward-slash. Nothing else.) For reference: [mod_rewrite / Regular Expressions](https://httpd.apache.org/docs/current/rewrite/intro.html#regex) – Markus AO Apr 08 '22 at 19:44

1 Answers1

1

you can use something like that :

  RewriteRule  items/ items/index.php [L]

if you want a genaric rule /any-folder/any-file.php to /any-folder/index.php

  RewriteRule  (\w+)/ $1/index.php [L]
Omar Tammam
  • 1,217
  • 1
  • 9
  • 17