最近我遇到了一个问题,当通过无规则路径访问某些页面时会出现 404 错误。
当查询字符串(如?1234
或)index.php
附加到路径时,相同的页面可以工作。
例子:
http://pagesofinterest.net/code/plugins/code-complete/- 失败
http://pagesofinterest.net/code/plugins/code-complete/?123- 成功
http://pagesofinterest.net/code/plugins/code-complete/index.php- 成功
我不确定这是 mod_rewrite 还是缓存问题。
这是我的.htaccess 文件的内容:
# Use PHP5.3 Single php.ini as default
AddHandler application/x-httpd-php53 .php
#ExpiresDefault A0
Header set Cache-Control "no-store, no-cache, must-revalidate, max-age=0"
Header set Pragma "no-cache"
DirectoryIndex index.php index.html
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.pagesofinterest.net [NC]
RewriteRule ^(.*)$ http://pagesofinterest.net/$1 [R=301,NC]
# Error documents
ErrorDocument 404 /404.php
ErrorDocument 403 /404.php
ErrorDocument 500 /500.php
# compress a few file extensions
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/atom_xml
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE text/html
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4.0[678] no-gzip
BrowserMatch ^MSIE !no-gzip !gzip-only-text/html
<IfModule mod_expires.c>
# explicitly disable caching for scripts and other dynamic files
<FilesMatch "\.(pl|php|cgi|spl|scgi|fcgi)$">
Header unset Cache-Control
</FilesMatch>
</IfModule>
Redirect /mikes http://pagesofinterest.net/blog/
Redirect /code-of-interest http://pagesofinterest.net/code
# Redirect all old photo pages to the tiny new one
RewriteCond %{REQUEST_URI} ^/photos/[a-z\/]+$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ http://pagesofinterest.net/photos/ [R=301,L]
答案1
这看起来有点奇怪,我们需要重写模块日志生成的错误(见https://httpd.apache.org/docs/current/mod/mod_rewrite.html有关如何启用 rewritelog 指令的更多信息)。问题似乎仅限于您的代码完成页面,因为菜单中所有可访问的链接都提供了有效的 URL/页面。
“快速修复/破解”方法是添加该页面的重定向。我不提倡这种方式,但有时我们只是希望它能起作用……
Redirect /code/plugins/code-complete /code/plugins/code-complete/index.php
Redirect /code/plugins/code-complete/ /code/plugins/code-complete/index.php
另外,顺便提一下,原始查询中丢失了“/”。我会将
RewriteRule ^(.*)$ http://pagesofinterest.net/$1 [R=301,NC]
为了
RewriteRule ^(.*)$ http://pagesofinterest.net$1 [R=301,NC]