URL重写 - preFER文件在其中pretty的网址目录 [英] Apache mod_rewrite - prefer files over directories with pretty URLs
问题描述
我想有pretty的URL,这样 http://www.domain.com/foo将返回 http://www.domain.com/foo.php
的问题在于存在具有相同名称的目录。我有另一个页面 http://www.domain.com/foo/bar/baz而现在我的服务器只返回foo的目录列表的时候,我要求 http://www.domain.com/foo
伪code:
如果请求加.PHP是一个文件
改写,而不是目录出文件
实际code:
RewriteEngine叙述上
的RewriteBase /
的RewriteCond%{SCRIPT_FILENAME} \ PHP -f
重写规则(。*)$ 1.PHP [NC,L]
您需要使用的整个路径:
的RewriteCond%{DOCUMENT_ROOT}%{} REQUEST_FILENAME的.php-f
REQUEST_FILENAME 里面只是完整路径 DocumenRoot
I want to have pretty urls so http://www.domain.com/foo will return http://www.domain.com/foo.php
The issue is that there is a directory that has the same name. I have another page at http://www.domain.com/foo/bar/baz and right now my server just returns the directory listing of foo when I request http://www.domain.com/foo
Pseudocode:
If the request plus ".php" is a file
rewrite out the file instead of the directory
Actual Code:
RewriteEngine On
RewriteBase /
RewriteCond %{SCRIPT_FILENAME}\.php -f
RewriteRule (.*) $1.php [NC,L]
You need to use the whole path:
RewriteCond "%{DOCUMENT_ROOT}%{REQUEST_FILENAME}.php" -f
REQUEST_FILENAME is just the full path inside DocumenRoot
这篇关于URL重写 - preFER文件在其中pretty的网址目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!