0

I want to rewrite every path to an index.php

with this code:

RewriteEngine on
RewriteRule ^(.*)$ index.php?_url_=$1 [L,QSA]

but when I type an invalid address my page redirect to 404.shtml (I guess)

for examle when I type:

1: http://sitename.com/image/a.png (which is exist) _url_ is image/a.png

2: http://sitename.com/nofolder/a.png (which is not exist) _url_ is 404.shtml

how is that possible when I rewrite everything to an existed index.php, still I get 404?

Pooya
  • 1,508
  • 3
  • 17
  • 38
  • The `index.php` don't redirect (in PHP) when url does not exist ? – Croises Nov 14 '14 at 21:02
  • exactly. that is why I wrote "I guess". I find out that from \_url\_ – Pooya Nov 14 '14 at 21:03
  • In this case, it's not a bug, it's a correct behavior... – Croises Nov 14 '14 at 21:05
  • I get this only in this server not other. and what should I do now? – Pooya Nov 14 '14 at 21:08
  • I will handle errors in php. if files are not exist then I'll show an error – Pooya Nov 14 '14 at 21:12
  • Verify whether your `.htaccess` is enabled or not, by putting same garbage (random) text on top of your `.htaccess` and see if it generates 500 (internal server) error or not? – anubhava Nov 14 '14 at 21:17
  • well I do that and I get 500. – Pooya Nov 14 '14 at 21:20
  • @Pooya Your current rule, would produce a 500 error and/or in some browser hit the redirect limit anyway as its a infinite LOOP redirecting index.php to itself. You could also define your 404 page to your index.php. – Prix Nov 14 '14 at 21:57
  • why LOOP? when a page redirect to index then that is done. I used to work with this in other server – Pooya Nov 14 '14 at 22:02
  • @Pooya its only done if you use apache 2.4+, which in this case its better to use END instead of L, apache 2.2 does not understand that and when you redirect from anything to index with no boundaries apache will enter a loop you can view the behavior in your RewriteLog. – Prix Nov 14 '14 at 22:12

0 Answers0