出于某种原因,在我的网站上,我只能访问根文件夹中的网站,如下所示:
http://domain-name.com/[file]
但我无法访问子目录。例如,以下内容不起作用:
http://domain-name.com/[folder1]/[file]
我使用Hostinger
作为我的虚拟主机。我感觉我的.htaccess
配置不正确。目前是.htaccess
:
RewriteEngine On
# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://domain-name.com/$1 [R=301,L]
# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ http://domain-name.com/$1 [R=301,L]
# Resolve .php file for extensionless php urls
RewriteRule ^([^/.]+)$ $1.php [L]
答案 0 :(得分:1)
您可以为所需的文件扩展名编写规则(以下为apache
和nginx
的示例):
# apache configuration
RewriteEngine on
RewriteRule !\.(js|gif|jpg|jpeg|png|ico|css|eot|svg|swf|ttf|woff|woff2|map|pdf|doc|docx|rar|zip)$ index.php
# nginx configuration
location / {
rewrite !\.(js|gif|jpg|jpeg|png|ico|css|eot|svg|swf|ttf|woff|woff2|map|pdf|doc|docx|rar|zip)$ /index.php;
}