Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rewrite all URL to index.php except from '/Serene/Assets/'

Tags:

php

.htaccess

So I've currently got all my URL's redirecting to index.php with this in my .htaccess:

RewriteEngine on
RewriteCond %{DOCUMENT_ROOT} !-f
RewriteRule ^(.*)$ index.php [QSA,L]

However, I need URLs such as http://localhost/Portfolio/Serene/Assets/css/style.css to not redirect, but I'm not sure how?

I'd really appreciate any help,

Cheers.

EDIT: Alternatively, I could tell the htaccess to not redirect any .js, .css, image files, etc, but again, I'm not too sure how to do this? Thanks!

EDIT2: I could also redirect anything ending in a .php or a path (such as /Portfolio/) to index.php, I have a feeling this may be easier.

EDIT3: Success, final code:

RewriteEngine on

RewriteCond %{DOCUMENT_ROOT} !-f
RewriteRule !\.(js|ico|gif|jpg|png|css|html|swf|flv|xml)$ index.php [QSA,L]
like image 579
chintanparikh Avatar asked Dec 17 '11 07:12

chintanparikh


2 Answers

Here's a another way to do it:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

images, robots.txt won't be rewritten to index.php. Just add your directories/files.

Hope that helps!

like image 80
ghstcode Avatar answered Nov 10 '22 20:11

ghstcode


This will rewrite requests for any files that don't exist on the server to index.php:

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

RewriteRule .* index.php [L]
like image 44
Seventoes Avatar answered Nov 10 '22 22:11

Seventoes