Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.htaccess css and image files redirection

I want to make it so if /css or /images path is requested... it redirects to the /images directory from the root but for all others I want it to direct to the pages directory.

I got the second part working... this redirect all to the pages directory

RewriteEngine on
RewriteCond %{REQUEST_URI} !pages/
RewriteRule (.*) /pages/$1 [L]

but I can't get the first part to work where if the user requests /css or /images it goes to the default folder rather than having /pages in the path.

My folder structure:

css
    css files
images
    image files
pages
    index.php
    about
        index.php
like image 945
TrickMonkey Avatar asked May 13 '26 07:05

TrickMonkey


1 Answers

You can add a RewriteCondition to prevent that

RewriteEngine on

RewriteCond %{REQUEST_URI} !\.(css|png|gif|jpg)$
RewriteCond %{REQUEST_URI} !pages/
RewriteRule (.*) /pages/$1 [L]
like image 61
Amit Verma Avatar answered May 14 '26 22:05

Amit Verma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!