您好,我已经研究这个问题好几天了,我还不太先进,请原谅我。
如果我有以下链接
<a href="<?=$linkLocations?>">Best Locations</a>
该变量定义如下:
$linkLocations = $URL . '/best-locations';
这在我的 .htaccess 文件中:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteRule ^([a-zA-Z0-9\_\-]+)$ subpage.php?page=$1 [NC]
RewriteRule ^([a-zA-Z0-9\_\-]+)/$ subpage.php?page=$1 [NC]
在 subpage.php 中:
if ($page == 'best-locations') {
include($ROOT .'/display/bestLocations.php');
$mainContent .= $locationContent;
}
并且 bestLocations.php 有 sql 查询等。 。但因为我得到了 404,我知道我还没有走得那么远,对吗?如果有帮助的话,这是在 wamp 上运行的实时站点的下载版本。您的意见是无以言表的珍贵
编辑- 通过从我的 .htaccess 中删除以下行解决了这个问题
# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
ExpiresActive On
ExpiresByType image/gif A2592000
ExpiresByType image/jpeg A2592000
ExpiresByType image/jpg A2592000
ExpiresByType image/png A2592000
ExpiresByType image/x-icon A2592000
ExpiresByType text/css A604800
ExpiresByType application/javascript A604800
ExpiresByType application/x-shockwave-flash A2592000
<FilesMatch "\.(gif¦jpe?g¦png¦ico¦css¦js¦swf)$">
Header set Cache-Control "public"
</FilesMatch>
最佳答案
失败的原因有很多。
“HTTP 404:Not Found”响应意味着未调用脚本 subpage.php(因此也是 bestLocations.php)。
您可能想要调试重写过程: How to debug Apache mod_rewrite
这个 .htaccess 有效吗?
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^([a-zA-Z0-9\_\-]+)/$ subpage.php?page=$1 [NC]
RewriteRule ^([a-zA-Z0-9\_\-]+)$ subpage.php?page=$1 [NC]
出于测试目的,我删除了与 HTTPS 相关的内容,并且还交换了最后的两行,以便先替换“x/”,然后替换“x”。
此外,您提到此代码是从某处下载的。该来源是否提到了所需的环境?这个可下载的系统可以在其他机器上运行吗?
更新 PS:为了 100% 确定您的服务器接受 .htaccess 文件:尝试在 .htaccess 文件中写入垃圾,并查看是否收到“HTTP 500:内部服务器错误”回复。如果不是,则不会解释您的 .htaccess。
关于php - .htaccess 影响我的 php 包括,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33313113/