最近,我遇到了一个问题,其中一些页面404通过他们的无止境的path访问。
查询string(如?1234或index.php被附加到path时,相同的页面工作。
例:
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还是一个caching问题。
这里是我的.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/[az\/]+$ RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ http://pagesofinterest.net/photos/ [R=301,L]
这看起来很奇怪,我们需要从重写模块日志中生成的错误(请参阅https://httpd.apache.org/docs/current/mod/mod_rewrite.html了解如何启用rewritelog指令的其他信息)。 该问题看起来像限制在您的代码完成页面,因为菜单中的所有可访问链接都提供了有效的URL /页面。
“快速修复/黑客”的方式将是为该页面添加redirect。 我不主张这种方式,但有时候,我们只是想让它工作…
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]