Da_programmer
Da_programmer

Reputation: 177

Folder and php file with the same name in website

How do i make it so this:

www.example.com/product

Will point to this file: /product.php but this:

www.example.com/product/thing.php

Will point to this directory: /product/thing.php

I have these rewrite rules in my .htaccess:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

It's making this:

www.example.com/product.php

Into this:

www.example.com/product

Upvotes: 2

Views: 1655

Answers (2)

Da_programmer
Da_programmer

Reputation: 177

I found out you can do something else that is almost as good.

www.example.com/product

becomes:

www.example.com/product/

If you add a 'index.php' or 'index.html' in the product directory on the web server. So the path becomes product/index.php, and the url will look like this:

www.example.com/product/

Upvotes: 0

hjpotter92
hjpotter92

Reputation: 80639

Toggle the DirectorySlash to Off.

DirectorySlash Off
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)$ $1.php [NC,L]

Upvotes: 4

Related Questions