.htaccess影响我的PHP包括


.htaccess affecting my php includes

大家好,我已经研究这个好几天了,我不是很精通,请原谅。

如果我有以下链接

<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)没有被调用。

你可能想要调试重写过程:如何调试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:内部服务器错误"响应。