doutu1939 2017-10-20 11:08
浏览 34
已采纳

使用.htaccess执行php如果找不到相同名称的目录

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".

  • 写回答

1条回答 默认 最新

  • dongyue8640 2017-10-20 11:56
    关注

    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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?