: .htaccess image localhost So I've created simple .htaccess file as following to make my webiste more SEO: # PROTECT FILES <FilesMatch ".(htaccess|htpasswd|ini|fla|psd|log|sh)$"> Order Allow,Deny
So I've created simple .htaccess file as following to make my webiste more SEO:
# PROTECT FILES
<FilesMatch ".(htaccess|htpasswd|ini|fla|psd|log|sh)$">
Order Allow,Deny
Deny from all
</FilesMatch>
#TURNED REWRITE ON
RewriteEngine on
#REWRITE CONDITIONS
RewriteRule start index.html
RewriteRule aboutMe about.html
RewriteRule contact contact.html
RewriteRule portfolio portfolio.php
RewriteRule reportage reportage.php
But the problem is that my images don't load properly. I used for them previously:
<?php
$files = glob("reportageImages/*.jpg");
for($i = 0; $i < count($files); $i++){
$imageDir = $files[$i];
echo '<li><img src="'.$imageDir.'" alt="reportage"/></li>';
}
?>
or directly without php:
<img src="reportageImages/lama.jpg"/>
and the directory was xamp/htdocs/MG/reportageImages/(here .jpg file) as I'm using xaamp to test my project.
I'm quite mislead by similar questions asked, as for some problems really sounding as mine works simply <base href="/" />, unfotunately not for me.
So I would really appreciate any help from you guys, I'm missing sth and tutorials over Internet don't cover all the topics. What worry me also is if in some way I would come over it, would the solution differ if I moved from local server to hosting?
Added photo to better visualize path problems:
Photos are counted well in directory ( I do same operation for each one and got relevant numbers of broken images boxes).
More posts by @BetL925
2 Comments
Sorted by latest first Latest Oldest Best
RewriteRule portfolio portfolio.php
RewriteRule reportage reportage.php
Sorry, just realised what's going on... you need to be more specific in your rewrites. The above rules will rewrite the URL if "portfolio" (or "reportage") appear anywhere in the requested URL - this will catch your image URLs as well (since "portfolio" and "reportage" are part of the URL path), and that's the problem. (I would expect this to also generate a rewrite loop - which would also result in a broken image. In this case the server's error log should give clues as to the "rewrite loop".)
Make your rules more specific, to match only the URL in the request. For example:
#REWRITE CONDITIONS
RewriteRule ^start$ index.html [L]
RewriteRule ^aboutMe$ about.html [L]
RewriteRule ^contact$ contact.html [L]
RewriteRule ^portfolio$ portfolio.php [L]
RewriteRule ^reportage$ reportage.php [L]
By adding anchors (^ and $) to the RewriteRule pattern it will now only match "portfolio" etc. exactly and also avoid a rewrite loop. The L flag ensures that no further rules will be processed in this pass.
I changed name of my folders to not conflict RewriteRule 's
Ex. Have reportageImages---> my .jpg here now its imagesR - name doesn't matter but it was in conflict someway with that RewriteRule:
RewriteRule reportage reportage.php
Now it works.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.