我还没有 /index/ 文件夹,如果我访问 myname.com/index/ 它会提取 index.php 上的数据但不显示 css,因为 /index/style.css 不存在。我已经用许多不存在的目录 url 对此进行了测试,都是一样的。
/about/ 调出 about.php 页面 /contact/ 调出 contact.php 页面
只有当我尝试加载不存在匹配的 .php 页面的 url 时才会发生 404。
示例:/blablabla/ 返回 404,因为 blablabla.php 不存在。
如何使 /about/ /contact/ /index/ 和其他具有匹配 .php 文件的目录返回 404?
这是我在 /etc/apache2/sites-available 中的配置文件的副本
<VirtualHost *:80>
ServerAdmin webmaster@yourname.com
ServerName yourname.com
ServerAlias www.yourname.com
DocumentRoot /var/www/yourname.com/public_html
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/yourname.com/public_html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /var/www/yourname.com/public_html/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
LogLevel warn
ErrorLog /var/www/yourname.com/logs/error.log
CustomLog /var/www/yourname.com/logs/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
<IfModule mod_expires.c>
ExpiresActive on
ExpiresByType image/jpg "access 1 month"
ExpiresByType image/gif "access 1 month"
ExpiresByType image/png "access 1 month"
ExpiresByType text/js "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType text/html "access 1 day"
ExpiresDefault "access 7 days"
</IfModule>
# Turn on Expires and set default to 0
ExpiresActive On
ExpiresDefault A0
# Set up caching on media files for 1 year (forever?)
<filesMatch "\.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav)$">
ExpiresDefault A29030400
Header append Cache-Control "public"
</filesMatch>
# Set up caching on media files for 1 week
<filesMatch "\.(gif|jpg|jpeg|png|swf)$">
ExpiresDefault A604800
Header append Cache-Control "public"
</filesMatch>
# Set up 2 Hour caching on commonly updated files
<filesMatch "\.(xml|txt|html|js|css)$">
ExpiresDefault A7200
Header append Cache-Control "proxy-revalidate"
</filesMatch>
# Force no caching for dynamic files
<filesMatch "\.(php|cgi|pl|htm)$">
ExpiresActive Off
Header set Cache-Control "private, no-cache, no-store, proxy-revalidate, no-transform"
Header set Pragma "no-cache"
</filesMatch>
# 480 weeks
<filesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Cache-Control "max-age=290304000, public"
</filesMatch>
# 2 DAYS
<filesMatch "\.(xml|txt)$">
Header set Cache-Control "max-age=172800, public, must-revalidate"
</filesMatch>
# 2 HOURS
<filesMatch "\.(html|htm)$">
Header set Cache-Control "max-age=7200, must-revalidate"
</filesMatch>
</VirtualHost>
这是 /var/www/yourname.com/public_html 中的 .htaccess 文件的副本
AuthName "Restricted Area"
AuthType Basic
AuthUserFile /var/www/yourname.com/.htpasswd
AuthGroupFile /dev/null
<Files admin.php>
require valid-user
</Files>
<Files systeminfo.php>
require valid-user
</Files>
我认为我的 .htaccess 中没有任何东西会导致这个问题。基本上我只是用密码保护位于父目录上的两个文件。