2

This exclude CSS/JS/Images from original url. Anyone know how to solve this problem ?

.htacess:

RewriteEngine on
RewriteRule %{REQUEST_FILENAME} !-d
RewriteRule %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?uri=$1 [QSA,L]

PHP:

$splitarray = explode('/',$_GET['uri']);
  • I explode URL using PHP to get 2nd parameter and include that page to index.php
6
  • You want css/js/images to be routed through index.php? Commented Jul 23, 2012 at 19:07
  • Yes. because i used PHP include() function to connect header/content pages/footer. kind of a simple framework that use simple method :) Commented Jul 23, 2012 at 19:14
  • Also, are you sure the first 2 RewriteRule lines aren't supposed to be RewriteCond? Commented Jul 23, 2012 at 19:18
  • but those 2 lines doesn't do anything in my case... :/ Commented Jul 23, 2012 at 19:23
  • Without those 2 lines, you should be routing all requests, including css/js/images, through index.php Commented Jul 23, 2012 at 19:24

1 Answer 1

3

Try:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_URI} \.(js|css|jpe?g|gif|png|bmp|ico)$ [NC]
RewriteRule ^(.+)$ index.php?uri=$1 [QSA,L]

So this will route through index.php if the request isn't for an existing directory and, the request isn't for an existing file OR the request isn't for a file ending with js, css, jpeg, jpg, gif, png, bmp, ico.

Sign up to request clarification or add additional context in comments.

3 Comments

images,js, now working fine but it doesn't pass uri to index.php !!! That's a big problem. :/
RewriteRule ^(.+)$ index.php?uri=$1 [QSA,L] Not working because RewriteEngine is off !!!
@stackminu Sorry, didn't mean to imply you want to get rid of the line turning on your rewrite engine. Just that you want to replace your RewriteRule lines with this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.