当重写引擎删除 .php
和 .html
时,我在访问索引文件时遇到了一些问题...
我在“public_html/user/username/index.php”中有一个索引 但当我尝试访问其中一个时,它会将我带到错误页面
mydomain.com/user/用户名或
mydomain.com/user/username/index 或
mydomain.com/user/username/index.php
当我尝试访问 public_html 文件夹中的文件夹中的任何文件时,比方说
public_html/user/username.php == mydomain.com/user/username <-- 有效
这是怎么回事?
我的.htaccess:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
重写引擎已启动,一切正常......
最佳答案
在添加这些扩展之前,您应该检查 php 和 html 文件是否存在:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^.]+)/?$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^([^.]+)/?$ $1.html [L]
关于php - 当重写引擎删除 .php 和 .html 时,无法访问文件夹中的索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31265871/