2

Hi there I have been on this one for days and I'm not too advanced forgive me.

If I have the following link

<a href="<?=$linkLocations?>">Best Locations</a>

with that variable defined so:

$linkLocations = $URL . '/best-locations';

and this in my .htaccess file:

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]

and this in subpage.php:

if ($page == 'best-locations') {
        include($ROOT .'/display/bestLocations.php');
        $mainContent .= $locationContent;
    }

And bestLocations.php has sql queries etc. . . but because I'm getting a 404 I know I'm not even getting that far right? This is a downloaded version of a live site running on wamp if that helps. Your input is prized beyond words

EDIT - This was solved by removing the following lines from my .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>
phillydigital
  • 193
  • 1
  • 11

1 Answers1

2

There are many reasons why this fails.

The "HTTP 404: Not Found" response means that the script subpage.php (and therefore also bestLocations.php) was not called.

You might want to debug the rewriting process: How to debug Apache mod_rewrite

Does this .htaccess work?

Options +FollowSymLinks

RewriteEngine on          

RewriteRule ^([a-zA-Z0-9\_\-]+)/$ subpage.php?page=$1 [NC]
RewriteRule ^([a-zA-Z0-9\_\-]+)$ subpage.php?page=$1 [NC]    

For testing purposes, I have removed the HTTPS relevant stuff, and I have also exchanged the two lines at the end, so that first "x/" gets replaced, and then "x".

Also, you mentioned that this code is downloaded from somewhere. Does this source mention something about the required environment? Did this downloadable system work on other machines?

Update PS: Just to be 100% sure that your server accepts .htaccess files: Try writing garbage in the .htaccess file, and see if you get a "HTTP 500: Internal Server Error" response. If not, then your .htaccess is not interpreted.

Community
  • 1
  • 1
Daniel Marschall
  • 3,739
  • 2
  • 28
  • 67