-2

I'm trying to include a image on my INDEX.php page but my HTACCESS blocks it when i visit the image by entering the url in the adress bar it shows a empty page

The link i'm trying to get the image from is http://127.0.0.1/ase/ts/

when i visit http://127.0.0.1/ase/ts/help.gif the page is loading slowly and not showing anything at all only a white page.

I cant get files at all from a /ASE/{SUBDIRECTORY}/

My .HTACCESS file for the /ASE directory

RewriteEngine On

RewriteRule ^(|/)$ index.php?url=$1
RewriteRule ^([a-zA-Z0-9_-]+)(|/)$ index.php?url=$1
RewriteRule ^([^/]+)/([^/]+)$ index.php?url=$1&page=$2 [NC,L]
RewriteRule ^(.*)\.htm$ $1.php [NC]

I think its because of this rule.

RewriteRule ^([^/]+)/([^/]+)$ index.php?url=$1&page=$2 [NC,L]

I am rewriting 127.0.0.1/ase/index.php?url=dash to 127.0.0.1/ase/dash and 127.0.0.1/ase/index.php?url=cmdlogs?p=1 to 127.0.0.1/ase/cmdlogs/1

SparK
  • 5,181
  • 2
  • 23
  • 32
  • 1
    It’s not “blocking” the images ... you just failed to take into account how the resolution of a relative URL into an absolute one works. – CBroe Apr 17 '18 at 11:52
  • https://www.google.com/search?q=htaccess%20rewrite%20images%20fail%20load shows you how frequently that topic has been discussed already, so please make a proper effort to go and inform yourself now. – CBroe Apr 17 '18 at 11:53
  • they all work but i dont get to see images from this one RewriteRule ^([a-zA-Z0-9_-]+)(|/)$ index.php?url=$1 because it blocks the directory ts – Je Boi Jesser Apr 17 '18 at 11:54
  • Then explain what exactly you mean by “blocked” please. Unless you are getting a 403 Forbidden or similar, calling this “blocked” would make rather little sense to begin with. My guess is, you are actually getting a 404, because ... (what I said in the very first comment already.) – CBroe Apr 17 '18 at 11:58
  • I'm getting an empty page because the link does not work but only image links are empty – Je Boi Jesser Apr 17 '18 at 11:59
  • _“I'm getting an empty page because the link does not work but only image links are empty”_ - that is basically gibberish that could mean anything or nothing. Please go read [ask] first of all now, and then edit your question to contain proper examples of what URL you are requesting your HTML document with (before, and after your rewriting attempts), and how exactly the image is embedded into that. – CBroe Apr 17 '18 at 12:09
  • Well `^([a-zA-Z0-9_-]+)(|/)$` should not match `ase/ts/help.gif` to begin with, so that particular rule is likely not to blame. – CBroe Apr 17 '18 at 12:40
  • `RewriteRule ^([^/]+)/([^/]+)$ index.php?url=$1&page=$2 [NC,L]` i mean. And i just found out JS files in the directory /ase/ts/ doesnt work either – Je Boi Jesser Apr 17 '18 at 12:50
  • So everything gets rewritten to your index.php ... now if that only outputs a “blank page”, then either you did not create any, or you are dealing with a PHP error that kills the script. https://stackoverflow.com/q/1475297/1427878 explains how to deal with the latter, so start with that. – CBroe Apr 17 '18 at 12:58
  • When i empty my `HTACCESS` file everything works correctly so its not a php error – Je Boi Jesser Apr 17 '18 at 13:07
  • What are you trying to accomplish with your htaccess? If you are attempting to redirect only a few requests but not others search for `RewriteCond` – SparK Apr 17 '18 at 13:12
  • _“When i empty my HTACCESS file everything works correctly so its not a php error”_ - yeah well duh, when you remove your rewriting, then the request for your image does _not_ get rewritten to the index.php, but is delivered normally by the web server ... You are comparing apples and oranges here. – CBroe Apr 17 '18 at 13:18
  • updated post to what the url should look like for single links and for pagination links @SparK – Je Boi Jesser Apr 17 '18 at 13:42

1 Answers1

0

What you are asking is: if the file exists then avoid redirection.

In that case add this line before the offending RewriteRules:

RewriteCond %{SCRIPT_FILENAME} !-f 

This will check exactly for that and skip your rewrite. Notice that only routes that would otherwise give you a 404 will be rewritten to your index file now, so make sure you don't have much files lying around your public folders.

SparK
  • 5,181
  • 2
  • 23
  • 32
  • More info here, if you can read portuguese: https://pt.stackoverflow.com/questions/102722/o-que-significam-rewritecond-e-rewriterule-em-um-arquivo-htaccess – SparK Apr 17 '18 at 14:33
  • put it before your `RewriteRule ^([^/]+)/([^/]+)$ index.php?url=$1&page=$2 [NC,L]` rule – SparK Apr 17 '18 at 14:48