简体   繁体   中英

Using .htaccess to Execute php if directory of the same name not found

I want to execute php if directory of the same name not found.It works well on Wamp because it's already configured in its Apache httpd.conf but I don't know what to do with .htaccess.
EX: www.example.com/directory1/directory2/...../.......
Actually There's no directory1 folder in the root but there's only a php file name "directory1.php"
so I want www.example.com/directory1/directory2/ to execute a php file name "directory1.php"
if the folder of that name is not found.
In Short, If there's a folder it'll follow that folder directory but if no folder then it'll execute the first directory which is in php file after website url without .php extension.
So That php should be able to execute with slash behind "www.example.com/directory1/" or without slash "www.example.com/directory1".

Check if the requested URL neither a directory nor a file, then rewrite to the PHP file with the Name of the first folder

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ([^/]+) $1.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM