Htaccess redirect all requests to index (does not allow images) Wamp Server

1.4k views Asked by At

Please I need a help. I am working on a site and wants to redirect all requests to an index file while allowing access to images, css, javascripts and other documents that are not php scripts. I am working on a local server (WAMP). The problem I have is that it redirects all requests to the index file including images. Below is my htaccess rule.

<IfModule mod_rewrite.c>

RewriteEngine On

RewriteBase /myapp
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(\d{4})/(0?[1-9]|1[0-2])/([^/]+)/?$ app/$1-$2/$3 [R=301,L]
RewriteRule ^(.*)$ index.php [L]
</IfModule>
2

There are 2 answers

2
Kieran On

Is this not what you're aiming for?

RewriteRule ^(.*\.php)$ index.php [L]

You should also escape those slashes in your first rewrite rule

0
andychukse On

Thanks I have figured it out, I just modified the moved the first rewrite rule above the rewrite condition and it now working fine.

<IfModule mod_rewrite.c>

RewriteEngine On

RewriteBase /myapp
RewriteRule ^(\d{4})/(0?[1-9]|1[0-2])/([^/]+)/?$ app/$1-$2/$3 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php [L]
</IfModule>