0

I am trying to create a page with the same name as a directory that it is supposed link to, e.g.

What happens is that when I name my directory of blog articles blog and then name php webpage blog as well. Then I try to open the PHP blog webpage it throws an error (it gets me to the index page).

I originally had different names for the directory and webpage but I saw on a couple other sites that they solved this issue, but I don't know how. It currently works if I write a link like href="/blog.php" instead of href="/blog" but then the URL has the .php suffix, which I'd like to avoid.

This is my current Apache (.htaccess) configuration:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
IMSoP
  • 89,526
  • 13
  • 117
  • 169
Adam
  • 23
  • 4
  • I highly recommend you read the reference answers here, to understand what your current configuration means, and what other options you have: [Reference: mod_rewrite, URL rewriting and "pretty links" explained](https://stackoverflow.com/questions/20563772/reference-mod-rewrite-url-rewriting-and-pretty-links-explained) – IMSoP Dec 01 '22 at 17:20
  • _"What happens is that when I name my directory of blog articles blog and then name php webpage blog as well."_ - you can't actually have done _exactly_ that - because you can not have a file and a folder with the same name. I am guessing what you actually mean is, that your script is named `blog.php`? And you used the shown rewrite configuration to "remove .php", as people commonly phrase it? – CBroe Dec 02 '22 at 07:32
  • @CBroe yeah thats right. The .php is removed by the .htaccess script. – Adam Dec 02 '22 at 12:19
  • _"Then I try to open the PHP blog webpage it throws an error (it gets me to the index page)."_ - that would likely be due to mod_dir automatically performing a redirect to add the trailing slash to `/blog` - and after that, the actually shown document, will be the index document for that folder. Your whole setup here is rather asking for trouble. If you can live with the initial URL being `/blog/` instead of just `/blog` - then this would be easiest to realize, if you just renamed/moved your `blog.php` to `blog/index.php` in the first place. – CBroe Dec 02 '22 at 12:26
  • @CBroe yeah alright. But what is the correct set-up website architecture setup for this inquiry? There has to be some standard approach to this... – Adam Dec 04 '22 at 17:57

0 Answers0